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

Roblox Touched Event And TouchEnded Event Broken Please Help?

Asked by 4 years ago
local part = script.Parent

part.Touched:Connect(function(hit)
        local H = hit.Parent:FindFirstChild("Humanoid")
                if H ~= nil then
                    print("player is in")
                end
end)

part.TouchEnded:Connect(function(hitended)
        local H = hitended.Parent:FindFirstChild("Humanoid")
                if H ~= nil then
                    print("player is not in")
                end 
end)

if I touched the part and not moving it prints "player is in" and "player is not in" I don't know how to fix the problem also if I moved it spams "player is in" and "player is not in" I don't know if touchedended and touched is working! please Help!

1 answer

Log in to vote
0
Answered by
Time_URSS 146
4 years ago
Edited 4 years ago

In my opinion, using those systems in big detector parts is problematic without a cooldown. So I suggest you use a cooldown system which is very easy to make.

EDIT: I forgot the thing that, even with the cooldown thing, it will still spam-print the text. The reason is that the function ends while the player is still in, so we need the function to yield until the player leaves. In this case, I will remove the TouchEnded event, as it won't be necessary.

local part = script.Parent

part.Touched:Connect(function(hit)
    local H = hit.Parent:FindFirstChild("Humanoid")
        if H ~= nil then
            print("player is in")
        end
    repeat wait() until not H
end)

part.TouchEnded:Connect(function(hit)
    local H = hit.Parent:FindFirstChild("Humanoid")
        if H ~= nil then
            print("player is not in")
        end
end)

If this still doesn't work, I'd suggest using Region3 instead of Touched Events

0
If it doesn't work, please tell me, as I might have forgotten some things in the script. Time_URSS 146 — 4y
0
Ain't working :C ImAnonymousBan 24 — 4y
0
I see, let me edit the answer a bit Time_URSS 146 — 4y
Ad

Answer this question