I need help. I made a script that plays a sound when you enter an object and it ends the sound ontouch end. Since touch end is glitchy the sound starts over when you jump. I need a fix to disable jumping onconnect with a part but I don't know how. Can someone help? This is what I have so far.
debounce = false
script.Parent.Touched:connect(
function(hit)
if debounce == false then
debounce = true
if (hit.Parent:FindFirstChild("Humanoid") ~= nil) then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local sound = script.Parent.Sound:Clone()
sound.Parent = player.PlayerGui
sound:Play()
sound.Ended:wait()
debounce = false
end
end
end
)
script.Parent.TouchEnded:Connect(
function(hit)
debounce = false
local playergui = game.Players:GetPlayerFromCharacter(hit.Parent).PlayerGui
if playergui.Sound then
local sound = playergui.Sound
sound:Destroy()
end
end
)

2 comments
didnt work
sorry