Hey everyone! I’m trying to make a script that detects if the player is touching a part and then turn a bool value to true, or false if he is not touching it. Anyways, the Touch function seems to be very buggy, as the player continues touching it, but the TouchEnded is still fired, and I got no idea how to make it work as intended.
Here’s the script:
local Verifier = script.Parent.Parent.Verifier
local CanAccess = script.Parent
local Debounce = false
Verifier.Touched:Connect(function(Enable)
if Enable.Parent:FindFirstChildOfClass("Humanoid") then
if Debounce then return end
Debounce = true
print("PC: ON")
CanAccess.Value = true
end
end)
Verifier.TouchEnded:Connect(function()
print("PC: OFF")
CanAccess.Value = false
wait(.2)
Debounce = false
end)
I don’t know what you mean. And I got no idea how I should proceed because not even errors are being showed in output
The code now is looking like this: (maybe is my fault I forgot to mention that I suck at scripting)
local Verifier = script.Parent.Parent.Verifier
local CanAccess = script.Parent
local Debounce = false
for i,v in pairs(Verifier:GetTouchingParts()) do
if game.Players:GetPlayerFromCharacter(v.Parent) then
print("do something")
return end
end
LOL.
Yeah, now I managed to make the script work again, but it’s still pretty much the same. The script says when I’m not touching when I still am, and sometimes the TouchEnded is not triggered