Make a sound play when a player is on a team?

Hello,
I have one small question.
I want a sound to play “client side” when a user is on the Innocent side, the detective side, and the traitor side.
I have no idea how to make a script that would do this. I really need some help, lol.

All help is welcome!

Then they join or while they are on team like all time?

[lua]
hook.Add(“TTTBeginRound”, “TTTBeginRound_SND”, function()
local LP = LocalPlayer()

if LP:IsTraitor() then
	surface.Playsound("ttt/cooltraitorsound.wav")
elseif LP:IsDetective() then
	surface.Playsound("ttt/cooldetectivesound.wav")
else
	surface.Playsound("ttt/coolinnosound.wav")
end

end)[/lua]

Ok so this is what I have :
[lua] hook.Add(“TTTBeginRound”, “TTTBeginRound_SND”, function()
local LP = LocalPlayer()

if LP:IsTraitor() then
	surface.Playsound("sound/pfst.mp3")
elseif LP:IsDetective() then
	surface.Playsound("sound/pfsd.mp3")
else
	surface.Playsound("sound/pfsi.mp3")
end

end) [/lua]

I 1st put it in: /lua/autorun/server/ttt.lua
But that does nothing…

Then I put it in: /lua/autorunclient/ ttt.lua
And that makes this lua error: [lua] [ERROR] lua/autorun/client/ttt.lua:9: attempt to call field ‘Playsound’ (a nil value)

  1. fn - lua/autorun/client/ttt.lua:9
  2. Call - addons/ulib/lua/ulib/shared/hook.lua:183
    3. RoundStateChange - gamemodes/terrortown/gamemode/cl_init.lua:138
    4. Function - gamemodes/terrortown/gamemode/cl_init.lua:214
    5. unknown - lua/includes/modules/usermessage.lua:87
    [/lua]

So where should I put this bit of code?

it’s surface.PlaySound, not surface.Playsound.

Now this ( [lua] [ERROR] lua/autorun/client/ttt.lua:9: attempt to call field ‘Playsound’ (a nil value) [/lua] would make scene, lol!
Let me give it a try.

Edit:
There is no longer an error…
But the sound does not play :
Any ideas?
(I know the FastDL worked)

Edit:
Oops, You need to remove “sound” from your path!

But thanks for the help guys! :zoid: