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!
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