I have this code im using for making sound jumpscares that play when you touch the part. It is a localscript in startercharacter because i want only the player who touches the part at the moment to be able to hear it.
My problem is that i want the sound to activate only once (only reset the trigger to work again if the player has died) but as of right now idk how. When i remove the wait the other parts that trigger sounds on touch stop working. Help would be greatly appreciated!
local played = false
workspace.JumpscaresChapter1:FindFirstChild("JumpscareChurch").Touched:Connect(function(hit) --Which jumpscare we coding
if played == false and hit.Parent:FindFirstChild("Humanoid") then
workspace.JumpscaresChapter1:FindFirstChild("GlassBreak"):Play() --these are Sounds and The Folder in the workspace
played = true
wait (5) --This Is delay after first play, you can change it if you want to
played = false --Ready to play again
end
end)
workspace.JumpscaresChapter1:FindFirstChild("JumpscareCrematoriumStairs").Touched:Connect(function(hit) --Which jumpscare we coding
if played == false and hit.Parent:FindFirstChild("Humanoid") then
workspace.JumpscaresChapter1:FindFirstChild("ScreamMonster"):Play() --these are Sounds and The Folder in the workspace
played = true
wait (5) --This Is delay after first play, you can change it if you want to
played = false --Ready to play again
end
end)
workspace.JumpscaresChapter1:FindFirstChild("JumpscareCrematorium1").Touched:Connect(function(hit) --Which jumpscare we coding
if played == false and hit.Parent:FindFirstChild("Humanoid") then
workspace.JumpscaresChapter1:FindFirstChild("Chirrido"):Play() --these are Sounds and The Folder in the workspace
played = true
wait (5) --This Is delay after first play, you can change it if you want to
played = false --Ready to play again
end
end)
workspace.JumpscaresChapter1:FindFirstChild("JumpscareCrematorium2").Touched:Connect(function(hit) --Which jumpscare we coding
if played == false and hit.Parent:FindFirstChild("Humanoid") then
workspace.JumpscaresChapter1:FindFirstChild("ScreamMonster2"):Play() --these are Sounds and The Folder in the workspace
played = true
wait (5) --This Is delay after first play, you can change it if you want to
played = false --Ready to play again
end
end)
workspace.JumpscaresChapter1:FindFirstChild("JumpscareCrematorium3").Touched:Connect(function(hit) --Which jumpscare we coding
if played == false and hit.Parent:FindFirstChild("Humanoid") then
workspace.JumpscaresChapter1:FindFirstChild("SteamPipe"):Play() --these are Sounds and The Folder in the workspace
played = true
wait (5) --This Is delay after first play, you can change it if you want to
played = false --Ready to play again
end
end)
