More Optimized Way To Know if Player is Running

Hello, I need help with something I’m making a speed simulator where the player gain points by running, is there a better way to know if a player is running because the script I use lags the player and not good for example like when I ran into a wall while still holding “W” the event still fires. Is there a better way to do this? I tried looking for solutions in the DevForum but none of them helped.

local player = game:GetService("Players").localPlayer
local remotes = game:GetService("ReplicatedStorage")

while wait(0.5) do
	if player.Character:FindFirstChildWhichIsA("Humanoid").MoveDirection.Magnitude > 0.1 then
		remotes.AddPoints:FireServer()
	end
end
2 Likes

You can use the Humanoid | Roblox Creator Documentation or Humanoid | Roblox Creator Documentation event to see if the state of the humanoid changes to running.

2 Likes

you can use GetPropertyChangedSignal for this:

humanoidRootPart:GetPropertyChangedSignal("Position"):Connect(function()
  --Do stuff
end)
2 Likes

Use Humanoid.Running for this type of stuff.

Humanoid.Running:Connect(function(speed)
    if speed > 0 then
        --add points
    end
end)
4 Likes

You can check by using velocity and magnitude. For example:

local speed = humanoid.RootPart.Velocity.magnitude
print(speed)
3 Likes

This doesn’t work because when you get the signal for CFrame or Position, the signal is only fired when a script edits the value and not when physics updates it.
So if you try this, you will see that the signal is never fired.

2 Likes

Humanoid.running should answer your question

1 Like

try this:

Capture

3 Likes

You kinda solved my problem I just edited the almost all the part of the script now it works haha… Thanks.

No problem this is why I joined the forum , to solve others problem and learn more

2 Likes