I want someone to touch the 'trigger' then a new sound is made and put in the players StarterGui so it plays only for them, but I don't want the sound to play another time for the player,I only want it to play once then the brick can identify who has gone through and who hasn't so the sound can't play a second time! I would like to have a debounce in it aswell, but I don't understand how to do it? Here is what I have so far:
function onTouched(Part) local SoundMaker = Instance.new("Sound", game.StarterGui) SoundMaker.SoundId = ("http://www.roblox.com/asset/?id = 156637449") local Sound = game.StarterGui.Sound Sound:Play() end
Much appreciated if anyone can help? :)
Okay, there's many errors here. You can copy and paste the full script below, and you can remove the comments if you'd like:
db = false --Debounce variable. False means the function will run and true means the function won't run. function onTouched(Part) if db then return end --If db is true, then stop the function. db = true --Set db to true so the function can't be repeated while it's true. if Part.Parent:FindFirstChild("Humanoid") and game.Players:GetPlayerFromCharacter(Part.Parent) then --If there is a Humanoid in the model and a player is found then... local plr = game.Players:GetPlayerFromCharacter(Part.Parent) --The player which is found. if plr.PlayerGui:FindFirstChild("onTouchSound") then return end local sound = Instance.new("Sound", plr.PlayerGui) --Make the sound sound.Name = "onTouchSound" sound.SoundId = "http://www.roblox.com/asset/?id=156637449" --No need for spaces in the SoundId sound:Play() --Play the sound end wait(2) --Change to how long you want the debounce delay to be. db = false --Sets db to false so the function can run again. end script.Parent.Touched:connect(onTouched)
script.Parent.Touched:connect(function(hit) local SoundMaker = Instance.new("Sound", game.StarterGui) SoundMaker.SoundId = ("http://www.roblox.com/asset/?id = 156637449") local Sound = game.StarterGui.Sound Sound:Play() Sound.Parent = hit.Parent end