--ok so I went by what kiiln said but it's saying that Players is not a valid member of workspace (line 5) Even though it is
local hasHit = false local scarepart = game.workspace.ScareBrick
scarepart.Touched:connect(function(partth) if partth.Parent:FindFirstChild("Humanoid") and game.workspace.Players[partth.Parent.Name] and not hasHit then local plr = partth.Parent local sound = scarepart.Sound:clone() sound.Parent = game.workspace.Players[plr.Name].PlayerGui sound:Play() hasHit = true end end)
Going to introduce you to anonymous functions
.
Now, to keep them from playing the sound too many times, you can use a debounce
.
Debounce makes it so they can't hit it more than once.
I'll also make it so if the players hits it, it will only play for THAT player, and not everyone in the server.
local hasHit = false --They haven't hit the part yet local soundBrick = game.workspace.ScareBrick --Where the Sound's parent is located soundBrick.Touched:connect(function(partThatHit) --This is an anonymous function if partThatHit.Parent:FindFirstChild("Humanoid") and game.Players[partThatHit.Parent.Name] and not hasHit then --If the model has a Humanoid, they are in the Player list, and they haven't hit it yet local plrCharacter = partThatHit.Parent local sound = soundBrick.Sound:Clone() --Getting the sound sound.Parent = game.Players[plrCharacter.Name].PlayerGui --Putting the sound in the player's PlayerGui sound:Play() --And play! hasHit = true --Now they hit it! end end) --After the function, it requires and end with a ) after it