I have this script that detect if a player is nearby by using a radius, I want a gui to show up when the player is inside the radius with tweening, and when the player leave the inside of the radius the gui will tween back to its hiding place. The problem is that when the player leave before the tween stop or while the tween is playing, the tween will stay there until the player come back to the radius and leave. How do I fix this?
UserInputService.InputBegan:Connect(function(input)
RunService.Heartbeat:Connect(function()
if (Center - Player.Character.HumanoidRootPart.Position).Magnitude <= Radius and not PlayerIn and not texton then
texton = true
PlayerIn = true
print(Player.Name.." is in the circle!")
text:TweenPosition(UDim2.new(0,462,0,500), 'Out', 'Quad', 0.2)
end
end)
end)
RunService.Heartbeat:Connect(function()
if (Center - Player.Character.HumanoidRootPart.Position).Magnitude > Radius and PlayerIn and texton then
PlayerIn = false
texton = false
text:TweenPosition(UDim2.new(0,462,0,700), 'Out', 'Quad', 0.2)
print(Player.Name.." is outside the circle!")
end
end)

3 comments
does it print
TweenPosition has a 5th argument: override. It's value is set to false by default but you might want to set it to true so other tweens will be able to override the current tween while playing if that's what you wanted.
Thanks! I didn't get what you were saying the first time, but it turns out that it was the correct answer.