In my obby, when you reach a checkpoint, I want it to play a sound. It'll only play once, not every time someone steps on it. The checkpoints use teams, so I figured that every time the team is changed it'll play the sound. How exactly do I code this?
LocalScript in StarterPlayerScripts
local Players = game:GetService("Players") local Player = Players.LocalPlayer local PlayerGui = Player.PlayerGui Player.Changed:connect(function(p) if p == "Team" then PlayerGui["SoundName"]:Play() end end)
And put a 'Sound' in the StarterGui. You can edit the properties of the Sound to how you like them a bit easier that way. Switch out the SoundName in the script to whatever your Sound is named.
Youll have to use an If statement and also a debounce. Both are fairly simple, I shall try to explain although I am not the best teacher.
So Im going to assume you have lots of teams, as obbies usually do. So its simple you can use a touched event and tell it to only fire 1 time. :)
Insert the script into the part, make sure its a script and not a local script.
local SoundSerivce = game:GetSerivce("SoundService") local Sound = "Your sound here" local AlreadyTouched = false if script.Parent.Touched and AlreadyTouched == false then Sound:clone().Parent = SoundService SoundService:PlayLocalSound(SoundService:WaitForChild("Sound")) AlreadyTouched = true end
So Ill explain now what the whole script does, It uses ROBLOX's soundservice to take your sound and clone it to sound service then it plays it locally which means only the player who touched the part hears it (I think... It should work).
It then sets the debounce to true meaning it cannot play again because alreadytouched needs to be false in order for the script to run.
Hopefully this works. I am not the best scripter but I do try my best :)