char.Torso.Changed:connect(function(prop) if prop == "Position" then local dis = (block.Position-char.Torso.Position).magnitude if dis <= maxDistance then gui.Frame.Visible = true print"Now you see me" else gui.Frame.Visible = false print"Now you dont" end end end)
Within the output it prints "Now you dont" "Now you dont" and then terminates.
EDIT: If it helps, here's the entire script
local player = game.Players.LocalPlayer if not player.Character then player.CharacterAdded:wait() end local char = player.Character block = game.Workspace:WaitForChild("Door") local maxDistance = 100 local gui = player.PlayerGui.Text local WaitTime = 0.001 local inProcess = false local active = false function open() for i=0,22 do block.CFrame = block.CFrame + Vector3.new(0,.5,0) wait(WaitTime) end active = true end function close() for i=0,22 do block.CFrame = block.CFrame + Vector3.new(0,-.5,0) wait(WaitTime) end active = false end char.Torso.Changed:connect(function(prop) if prop == "Position" then local dis = (block.Position-char.Torso.Position).magnitude if dis <= maxDistance then gui.Frame.Visible = true print"Now you see me" else gui.Frame.Visible = false print"Now you dont" end end end) game:GetService("UserInputService").InputBegan:connect(function(key,gameThing) if key.KeyCode == Enum.KeyCode.Space then--and not gameThing and gui.Visible then if inProcess ~= true then inProcess = true if active ~= true then open() else close() end inProcess = false end end end)
Changed doesn't fire for Physics
If I recall correctly
It's annoying, and it's also incredibly stupid. The only real way you're going to get those sorts of things checked is with a polling loop. Sorry about that. You'll have to look for a different event to check (How about one from the Humanoid?), or use a while loop.
I used MoveDirection
under the LocalPlayer's Humanoid. It only has a value when the player is moving.