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

Why does this only fire once?

Asked by
Zerio920 285 Moderation Voter
9 years ago

I've got this server script:


game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(char) char.Torso.Changed:connect(function(look) print(char.Torso.CFrame.lookVector) end) end) end)

It's supposed to return the lookvector of the player's torso when it changes, however this doesn't work after the first few times for whatever reason.

EDIT: Tried using a repeat:

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(char)
        wait()
        repeat
            print(char.Head.CFrame.lookVector)  
            wait(0.1)
        until
        char.Head ~= nil
    end)
end)

Only fires once now for some reason.

1 answer

Log in to vote
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

Physics won't fire the Changed event consistently, so I would only expect to see this event fired when the player was somehow teleported.

Consider instead using a repeating loop, or just checking the lookVector whenever you require it (in whatever function / event / loop that is)

0
That makes sense. I'd need the LookVector whenever it changes but there isn't a property that would help me with that it seems. Zerio920 285 — 9y
0
If you're in a LocalScript, you can use the RenderStepped event to fire as fast as possible. For many purposes, though, 30 times a second should be sufficient with a simple while wait() loop. BlueTaslem 18071 — 9y
Ad

Answer this question