I am trying to make it so that a value is true whenever you are touching the scripts parent, however i'm having a lot of trouble. The Touch Ended is not reliable enough as it constantly goes off even when the player is still on the part, it is too inconsistent, and since the Touched function usually activates only once, the value stays at false even though you are still touching it. I have put my full script and a simplified version of the script I'm using below. Anyone know what I should do?
FULL SCRIPT
part=script.Parent
ColorActive="Forest green"
ColorInActive="Institutional white"
part.Touched:connect(function(hit)--This only activates once usually
if hit.Parent:FindFirstChild("Humanoid")~=nil then
touch = true
local Touching=script.Parent.Touching
part.BrickColor=BrickColor.new(ColorActive)
repeat
--print"Touching"
Touching.Value=true
wait(1)
until not touch
part.BrickColor=BrickColor.new(ColorInActive)
Touching.Value=false
end
end)
part.TouchEnded:connect(function() touch = false end)--If this activates while a person is still on it, then it won't activate again until they get off and get back on.
SIMPLE
part.Touched:connect(function(hit)--This only activates once usually
touch = true
repeat
wait(1)
script.Parent.Touching.Value=true
until not touch
script.Parent.Touching.Value=false
end)
part.TouchEnded:connect(function() touch = false end)----If this activates while a person is still on it, it won't activate again until they get off and get back on, which isn't supposed to happen
