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)

2 comments
What I tried was using Humanoid and just purely using the Changed event from that. I was able to get it to work just fine after removing the if statement checking for position as well.
Yeah but Changed doesn't fire for Position, for physics updates.