HELP : Looping a song for a Job

Hi everybody !
I’m trying to make a Star Wars server, and I need my Darth Vader to be able to breathe like in the movies.
I already have the sound of " one breathe" that I would like him to be able to emit again and again with an editable amount of time btwn both, using one time the command " breathe" in the chat, or even better, when he gets the job directly, and stop the loop with a command too.
I’m stuck with this so far, as a beginner in Lua, I don’t know how to check his Team ( which is TEAM_VADER ) and to create the loop, for the moment the sound is playing only one time.

Any help would be highly appreciated

Thanks for all, Barbecue.


local chatSounds = {
					{msg = "/breathe", sound = "weapons/vadorbp2/vadorbp1.mp3"},
				
}

hook.Add("PlayerSay", "ChatSounds", function(ply, msg)
	for k, v in pairs(chatSounds) do
		if (string.find(msg, v.msg)) then
			ply:EmitSound(v.sound)



		end
	end
end )




To check it a player is the job TEAM_VADER do

if ply:Team() == TEAM_VADER then

On the job change hook you can create a timer that loops indefinitely after x seconds, then on job change you can destroy that timer. Make sure you use a unique timer, like the last 10 digits of their steamID of somesort.

[editline]2nd March 2017[/editline]

Also storing your command / sound in the table then looping over the table is unnecessary. Just create a local variable for the sound / command then use your check, no need for a table if you only have 1 key.