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

Trying to make a script that when you touch a part, it waits then sees if your still touching it?

Asked by
TNTeon -1
5 years ago
Edited 5 years ago

This is my code.

    local part = script.Parent --part
`while true do`

    wait(0.05)

    part.Touched:Connect(function()
        local z = 0
        wait(1)
        z = z + 1
        part.TouchEnded:Connect(function()
            z = 0
        end)
        if z == 5 then
            print("got it")
        end
    end)
    end

I want it so if they are touching it for more then 5 seconds it should print got it, but I reserved no message in the output view, not even an error. I would really appreciate some help!!

0
Don't use a loop for this; it's just going to keep setting up `touched` events every time the loop fires. TheeDeathCaster 2368 — 5y
0
GetTouchingParts awfulszn 394 — 5y
0
what should I do then?? TNTeon -1 — 5y
0
while #part:GetTouchingParts() > 0 do DeceptiveCaster 3761 — 5y

Answer this question