How do i detect when a player is moving?

I am currently trying to make the character get 1 “point” every 4 seconds while moving, but i cant really
figure out how. Despite looking at other posts, i still cant get it to work, and movedirection + runservice wont work for me either.

help appreciated :]

1 Like
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local Hum = char:WaitForChild("Humanoid")
Hum:GetPropertyChangedSignal("MoveDirection"):Connect(function()
if Hum.MoveDirection.Magnitude > 0 then
print("Moving")
end
end)
end)
end)

doesnt seem to work. i’m putting the script in StarterPlayerScripts, and im pretty sure this doesnt work locally, this may be the reason? i would prefer do do it locally tho.

why do you prefer to do it locally?

it doesnt seem to work either…

well, basically im making a superpower game and im making all the stats improve as you do things, like movement. and ive got it all in one local script, that handles it all and i wanna put it in there

its a bad practice to handle those type of stuff in localscripts your game could easily get exploited.

and it doesnt work server for me either

ok thanks, ill use that advice

ill try again in serverscriptservice
nope, doesnt work

this would work.

game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local Hum = char:WaitForChild("Humanoid")
Hum:GetPropertyChangedSignal("MoveDirection"):Connect(function()
if Hum.MoveDirection.Magnitude > 0 then
print("Moving")
end
end)
end)
end)
1 Like

yeah thanks that works perfectly!

1 Like

I use this sometimes to detect if something is idle:

local function IsIdle(Part) -- Hacky method to detect if character is idle, adds up their linear velocity (x,y,z) as a positive value and compares to a pre-calculated threshold (.001)
    local v = Part.AssemblyLinearVelocity
    --print(math.abs(v.X)+math.abs(v.Y)+math.abs(v.Z)) -- print velocity
    if math.abs(v.X)+math.abs(v.Y)+math.abs(v.Z) < .001 then
        return true
    end
end

if IsIdle(Character.PrimaryPart) then
    print("Is not moving")
else
    print("Is moving")
end

@ayoub50’s method should work too, but only for Humanoid objects afaik.

1 Like

thx, ill be able to use this too :smiley:

1 Like