Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Touched event from the part works for 3 times, then stops working?

Asked by 5 years ago
Edited 5 years ago

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)

1 answer

Log in to vote
-2
Answered by 5 years ago

Remove All Debounces

0
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. turtle2004 167 — 5y
0
I cant remove all debounces, it will spam the touch event. jdm4llfem8 94 — 5y
Ad

Answer this question