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

How would I be able to track player speed?

I made this hoping I will be able to track the speed of players but it always shows 0m/s

-- Create a new screen GUI
local screenGui = Instance.new("ScreenGui")
screenGui.Name = "SpeedTracker"
screenGui.Parent = game.Players.LocalPlayer.PlayerGui

-- Create a frame to hold the player speed labels
local frame = Instance.new("Frame")
frame.Size = UDim2.new(1, 0, 1, 0)
frame.BackgroundTransparency = 1
frame.Parent = screenGui

-- Create a label for each player
for _, player in pairs(game.Players:GetPlayers()) do
  local label = Instance.new("TextLabel")
  label.Size = UDim2.new(0, 100, 0, 20)
  label.BackgroundTransparency = 1
  label.Text = player.Name .. ": 0 m/s"
  label.Parent = frame
end

-- Update the player speed labels every frame
game:GetService("RunService").RenderStepped:Connect(function()
  for _, player in pairs(game.Players:GetPlayers()) do
    local label = frame:FindFirstChild(player.Name)
    if label then
      label.Text = player.Name .. ": " .. player.Character.Humanoid.WalkSpeed .. " m/s"
    end
  end
end)

7 comments

1

You are not setting the TextLabel's name to the player's name.

0

wdym? would love If you can help more, thanks

0

try .Stepped instead of .RenderStepped if the loop itself isn't running. Also make sure to position the labels accordingly. This should be a localscript

0

when adding .stepped, the script just doesn't work. the whole thing breaks

0

On line 24, you are using the FindFirstChild method to find a child with the player's name. Since you are not setting the TextLabel's name to the player's name, the method is returning nil so it will not update the text.

0

To change the name of the TextLabel, just do 'label.Name = player.Name', after line 14.

0

thank youuuu

1 answer

not sure if this will work, but try doing this. add a Server Script and add a ScreenGui to starter Gui

 game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(character)
		local frame = Instance.new("Frame")
		frame.Size = UDim2.new(1, 0, 1, 0)
		frame.BackgroundTransparency = 1
		frame.Parent = plr.PlayerGui:WaitForChild("ScreenGui")

		local label = Instance.new("TextLabel")
		label.Size = UDim2.new(0, 100, 0, 20)
		label.BackgroundTransparency = 1
		label.Text = plr.Name .. ": 0 m/s"
		label.Parent = frame
		while wait() do
			label.Text = math.ceil(math.abs(character.HumanoidRootPart.AssemblyLinearVelocity.X + character.HumanoidRootPart.AssemblyLinearVelocity.Z)).."m/s"
		end
	end)
end)

9 comments

0

While the code for this is functional, WalkSpeed isn't the Player's speed in meters per second, but in studs per second. Due to a stud being 28 centimeters, you have to multiply WalkSpeed by 0.28 for it to actually be in meters per second.

0

how would I be able to do that @dindin

0

character.Humanoid.WalkSpeed * 0.28 .."m/s"

0

it still shows 0m/s, idk the code seems right but idk why it won't update when a player moves

0

do this. label.Text = Character.HumanoidRootPart.AssemblyLinearVelocity.."m/s"

0

idk man I tried that too and it still doesn't change, thanks for trying though!

0

I am going to try to fix this on studio itself.

0

thank you, keep me updated!

0

just got if fixed, ima edit my answer.

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