#How would I check if the player is moving?

69 messages · Page 1 of 1 (latest)

shrewd sky
#

check every 0.1 second if the position of the humanoidrootpart is the same

shrewd sky
#

yeah

#

dont know other methods

opaque wing
#

Hold on let me find it

#

Look at this

shrewd sky
#

thanks

west ice
#

The Humanoid has a property called MoveDirection which determines, as a unit vector, the direction a player is moving in. You can access the Magnitude property and see if it’s greater than 0 to know if there is active movement without relying on what their HumanoidStateType is.

barren wadi
#

no

#

that's a single for loop

#

a game has normally dozens of for loops that iterate over hundreds of entities

#

you can make it event based though if that worries you 🤷‍♂️

#

is just a bit harder

west ice
#

movedirection?

#

i'll try it and see if it works

#

ok?

#

are you doing this for the walk animation?

#

because if you are there is a much simpler way of doing this

#

WOAH!!!

#

dont disrespect lua like that

#

just make states

#

|:

#

lemme just make it and i'll show you

#
local players = game:GetService("Players")
local runservice = game:GetService("RunService")

local plr = players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()


runservice.RenderStepped:Connect(function()
    local hum = char:FindFirstChild("Humanoid")
    if hum then
        local dir = hum.MoveDirection.Magnitude
        if dir > 0 then
            plr.State.Value = "Moving"
        else
            plr.State.Value = "Idle"
        end
    end
    print(plr.State.Value)
end)
#

this is what i did

#

i also made a string value inside the player when they join

#

it works

#

whenever im still it prints idle and whenever i move it prints moving

#

what?

#

pathetic

#

last time i went to sleep was 2 days ago at 11:30pm

shrewd sky
#

studio** You are now Level 4! **studio

west ice
#

because i like helping ppl on dev forum

#

no they aren't xd

#

i started 2 months ago and i'm already an extremely good coder

#

that is true

#

but i dont want to do this my entire life xd

#

direction

#

doesn't really matter

#

for free

#

i would die of poorness

#

ooooooooooooooh

#

i would be able to buy a happy meal with that kind of money

#

you're smart

#

an adult happy meal lmao

#

no i would not

#

i can beat on of those in a fight

#

they are very steppable

#

AMONGUS

#

AMOGUS

#

on a real note though does everything work?

#

is your char called safeRemain

#

i was just checking

#

you have to do character:WaitForChild("Humanoid")

#

or you could ```lua
local hum = character:FindFirstChild("Humanoid")
if hum then
-- code
end

shrewd sky
#

always wondered that

west ice
#

but im not sure

shrewd sky
shrewd sky
west ice
#

have you actually made the state string value yet

#

(server script)

local players = game:GetService("Players")

players.PlayerAdded:Connect(function(plr)
    local state = Instance.new("StringValue", plr) state.Name = "State"
end)
#

you aren't stupid

west ice
#

ok

shrewd sky
#

you could check if W, A, S, D are being clicked

#

or whatever the moving keybinds are