Walkspeed counter

Ok so, im trying to make a game like csgo surf and i have made a gui but im working on the walkspeed counter (it counts the speed that you are moving at) and just cant figure out what im doing wrong. and worse my studio crashed and i lost the script. so can someone help me on making this?

doesnt work for me. heres my script script.Parent.Value = HumanoidRootPart.Velocity.Magnitude

i also tried with humanoidrootpart

and how do i define it? im sorry im really confused

ok i did but still nothing

30characters

i can send a link to my game:isarvety's Place Number: 68 - Roblox

studio file too if you want to

local wfc = game.WaitForChild

local player = game.Players.LocalPlayer

local char = player.Character

local humanoidrootpart = wfc(char, “HumanoidRootPart”)

while true do

wait()

if humanoidrootpart == nil then return end

print(humanoidrootpart.Velocity.Magnitude)

end

while true do

script.Parent.Value = humanoidrootpart.Velocity.Magnitude

wait(1)

end

nuclear i dont know what going on but its still not working

can i send you the studio file so you can check it out?

Just a few tips:

  1. You can use spawn(func) to achieve a similar result as Nuclear’s suggestion: coroutine.resume(coroutine.create(func))
  2. I would recommend (although wait() works fine) using RunService.Heartbeat:Wait() instead of wait() in the case of velocity checking since it should stay synced with physics. (Generally physics related things should be synced with Heartbeat in this way for more consistent/reliable results but it’s not necessary)
  3. You may want to merge your prints with the counter to improve performance. If you’re displaying this information on a GUI you can instantly update information from a value using Value:GetPropertyChangedSignal("Value") or you can directly update the GUI from your script.

Your script can also be placed in StarterPlayer.StarterCharacterScripts which will place the script into the player’s character each time they spawn.

local player = game.Players.LocalPlayer
local char = player.Character
local humanoidrootpart = char:WaitForChild("HumanoidRootPart")

while true do
    wait()
    if humanoidrootpart == nil then return end
    print(humanoidrootpart.Velocity.Magnitude)
end

Try this. The original code had the following issues, from my knowledge:

  1. The wfc variable. You did not need to do that.
  2. local humanoidrootpart = wfc(char, "HumanoidRootPart") I do not believe that the second argument takes another string; rather, it takes a number, which is the timeout, in seconds.

I’m a bit unsure on how you’re doing movement, but since you mentioned WalkSpeed, the Running event is an event of humanoid that fires when a Humanoids WalkSpeed changes. Speed is even passed as a parameter for the event.

Alternatively, there is a function called GetPropertyChangedSignal which you could use to listen to changes in a part’s property, e.g. velocity. Ideally you would use this in a local script, disconnect the functions when the character dies and reconnect them when the new character spawns. (This would be if you’re not using WalkSpeed)

local chr = pathToCharacter
local part = chr:WaitForChild("Humanoid") 

local function VelocityChanged()
-- get part velocity, update gui
end

part:GetPropertyChangedSignal("Velocity"):Connect(VelocityChanged) 

I haven’t tested it but this should work.

1 Like

uhm it still doesnt work. can i send the studio file

Can you provide your current code?

A valid point. I never use it. But how did my code work otherwise? Did it fix or no?

I don’t think you can pass anything other than an integer/float into the second argument of :WaitForChild()

1 Like

If it works, then why is @isarvety having an issue? I’ll test the code and see what problem he’s having.

I have an issue when placing a LocalScript under StarterPlayerScripts. I’ll test further tomorrow.

Steps:

  1. Add a new LocalScript to StarterGui like so: fordf(1)

  2. Paste this code inside the LocalScript:

    local player = game.Players.LocalPlayer
    local char = player.Character
    local humanoidrootpart = char:WaitForChild("HumanoidRootPart")
    
    while true do
        wait()
        if humanoidrootpart == nil then return end
        print(humanoidrootpart.Velocity.Magnitude)
    end
    
  3. Watch the magic

1 Like