I'm trying to make a few animated jumpscares but for that to be properly complete I'll need to add sound once the animation is triggered which I don't know how to do and how I can make the block delete itself to prevent being triggered again. Anyone got a solution or good alternatives?
local players = game:GetService("Players") local part = workspace.Part local sound = part.Sound local triggered = false part.Touched:Connect(function(hit) --detects if ANYTHING hits it, what you see in the functions paranthesis is what touched it. if players:GetPlayerFromCharacter(hit.Parent) and triggered == false then --this line here makes sure that whatever touched the part is a player, not an npc or any other inanimite object. triggered = true --this sets the variable triggered to true because that will stop the sound from spamming due to roblox's touch event being a little bit weird. sound:Play() part:Destroy() end end)
looks self-explanatory, if you want to understand how it works then comment