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

Part keeps acting like the touch ended every 5 seconds?

Asked by 5 years ago
local touched = false

script.Parent.Touched:Connect(function(hit)
    local HRP = hit.Parent:FindFirstChild("HumanoidRootPart") or hit.Parent:FindFirstChild("Handle")
    if HRP then
        if not touched then
            touched = true
            script.Parent.Parent:FindFirstChild("Head").robotic_growling:Play()
        end
    end
end)

script.Parent.TouchEnded:Connect(function(hit)
    local HRP = hit.Parent:FindFirstChild("Torso") or hit.Parent:FindFirstChild("Handle")
    if HRP then
        if touched then
            touched = false
            script.Parent.Parent:FindFirstChild("Head").robotic_growling:Stop()
            wait()
            script.Parent.Parent.Name = "??????"
        end
    end
end)

while true do
    wait()
    if touched then
        local random = {"??????", "???????", "????????", "???????", "????????", "?????????", "??????????????????", "???????"}
        script.Parent.Parent.Name = random[math.random(1,#random)]
    end
end

yeah so basically it keeps acting like TOUCHENDED started while im still touching the part (the part has cancollide off)

0
The Touched event is terrible for this kind of thing. Try using Region3. Azarth 3141 — 5y
0
You need a wait(1) or some other wait time when using debounce. User#29785 0 — 5y

Answer this question