Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why does this only fire once?

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

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)

2 comments

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.

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.