im making a water script (please dont ask why) and its supposed to use a bodyposition to make it float. It does work but for some reason it only works for 3 times, and sometimes it doesnt even work.. why?
local debounce = false
script.Parent.Touched:Connect(function(hit)
if not debounce then
if hit.Parent.Torso then -- i did this because sometimes a accesory will get hit
debounce = true
local yes = game.Players:GetPlayerFromCharacter(hit.Parent)
game.Workspace.deletethingy:FireClient(yes)
wait(0.00001)
local e = Instance.new("BodyPosition")
e.Name = "Water"
e.Parent = hit.Parent.Torso
e.MaxForce = Vector3.new(4000,4000*e.Parent.Parent.UpDownMultiplier.Value*10,4000)
local m = game.Lighting.waterscript:Clone()
m.Parent = e
wait(0.3)
debounce = false
end
end
end)
script.Parent.TouchEnded:Connect(function(hit)
if not debounce then
if hit.Parent.Torso then
debounce = true
local e = hit.Parent.Torso:WaitForChild("Water")
e:Destroy()
wait(0.3)
debounce = false
end
end
end)

2 comments
This is possibly the worst 'answer' I've seen. One sentence? No information. Don't try to answer to get reputation, you won't get it. This is a help website, not a game so don't bother if you think that it's all about reputation, this is about helping people and giving new views/insight into problems. Sorry if this was over the top but it had to be said.
I cant remove all debounces, it will spam the touch event.