Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does this execute only twice?

Asked by 8 years ago
01char.Torso.Changed:connect(function(prop)
02    if prop == "Position" then
03        local dis = (block.Position-char.Torso.Position).magnitude
04        if dis <= maxDistance then
05            gui.Frame.Visible = true
06            print"Now you see me"
07        else
08            gui.Frame.Visible = false
09            print"Now you dont"
10        end
11    end
12end)

Within the output it prints "Now you dont" "Now you dont" and then terminates.

EDIT: If it helps, here's the entire script

01local player = game.Players.LocalPlayer
02if not player.Character then player.CharacterAdded:wait() end
03local char = player.Character
04block = game.Workspace:WaitForChild("Door")
05local maxDistance = 100
06local gui = player.PlayerGui.Text
07local WaitTime = 0.001
08local inProcess = false
09local active = false
10 
11function open()
12    for i=0,22 do
13        block.CFrame = block.CFrame + Vector3.new(0,.5,0)
14        wait(WaitTime)
15    end
View all 52 lines...

2 answers

Log in to vote
0
Answered by 8 years ago

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.

0
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. M39a9am3R 3210 — 8y
0
Yeah but Changed doesn't fire for Position, for physics updates. User#6546 35 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

I used MoveDirection under the LocalPlayer's Humanoid. It only has a value when the player is moving.

Answer this question