A couple of issues I’d like to raise with your repro.
-
PlayerScripts has superseded placing scripts directly in StarterGui. Handling conditions for new characters is up to the developer.
-
Do yourself and your potential collaborators a favour, teach yourself to use GetService to fetch a service and hold it in a variable.
-
You don’t account for an uninitialised character. If your code runs before a character is present, it will throw an error as your code assumes a truthy return for the WaitForChild statement. You can prevent this by yielding the thread until the required signal is fired and presents your needed item.
-
A while loop has a conditional argument. Returning end if a condition isn’t met isn’t the proper way to terminate a loop, it’d be break. Return does exit out of the loop’s scope but break is the proper operator. In addition, you can just use the conditional part properly1.
1:
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local characterRoot = character:WaitForChild("Humanoid")
while characterRoot do
print(characterRoot.Velocity.Magnitude)
wait()
end
Now obviously I have no clue if the code itself in concept works, that’s up for a test to reveal. Not as in my specific code, this whole printing of the character’s velocity.