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

How would I be able to track player speed?

Asked by 1 year ago

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)

1
You are not setting the TextLabel's name to the player's name. xInfinityBear 1777 — 1y
0
wdym? would love If you can help more, thanks Aliamasion 4 — 1y
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 greatneil80 2647 — 1y
0
when adding .stepped, the script just doesn't work. the whole thing breaks Aliamasion 4 — 1y
View all comments (3 more)
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. xInfinityBear 1777 — 1y
0
To change the name of the TextLabel, just do 'label.Name = player.Name', after line 14. xInfinityBear 1777 — 1y
0
thank youuuu Aliamasion 4 — 1y

1 answer

Log in to vote
0
Answered by 1 year ago
Edited 1 year ago

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)
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. DindinYT37 246 — 1y
0
how would I be able to do that @dindin Aliamasion 4 — 1y
0
character.Humanoid.WalkSpeed * 0.28 .."m/s" bittyboy1234 91 — 1y
0
it still shows 0m/s, idk the code seems right but idk why it won't update when a player moves Aliamasion 4 — 1y
View all comments (5 more)
0
do this. label.Text = Character.HumanoidRootPart.AssemblyLinearVelocity.."m/s" bittyboy1234 91 — 1y
0
idk man I tried that too and it still doesn't change, thanks for trying though! Aliamasion 4 — 1y
0
I am going to try to fix this on studio itself. bittyboy1234 91 — 1y
0
thank you, keep me updated! Aliamasion 4 — 1y
0
just got if fixed, ima edit my answer. bittyboy1234 91 — 1y
Ad

Answer this question