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.
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.
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
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)
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.