Hi how could i check if a players walking?
can this be used in a server script thats located in the character?
You can either check for this state:
Enum.HumanoidStateType.Running
to check if they are on the ground and running, or you could try ControlModule:GetMoveVector()
for the raw movement direction. Note that the two methods for retrieving move direction will not only happen when the player is running.
Humanoid.MoveDirection
is a property of the Humanoid
, and it does replicate to the server. So yes, you could use it in a server script inside the character. Basically, any script that runs and can access it will work.
Alright great also if i wanted to use Enum.HumanoidStateType.Running would i have to do something like this?
if humanoid.HumanoidStateType == Enum.HumanoidStateType.Running then
--code
end
No, to get the current HumanoidStateType
, you need to use the Humanoid method GetState
. But, if you want to detect when it is changed, you can use Humanoid.StateChanged
.
local state = Humanoid:GetState() --> returns the current Enum.HumanoidStateType of the humanoid
Humanoid.StateChanged:Connect(function(old: Enum.HumanoidStateType, new: Enum.HumanoidStateType)
print(old) --> the previous state of the humanoid
print(new) --> the new state of the humanoid
end)
but how would i use that to check if the player is moving/running??
Well, you kinda got two options. You can use Humanoid.MoveDirection
like @ronaldbox suggested, which tells you the actual vector direction the humanoid is moving in. It changes whenever your character changes direction, but you can link a function to run when it changes with Humanoid:GetPropertyChangedSignal("MoveDirection")
.
Or, you can use ControlModule:GetMoveVector()
. This only works on the client, and it returns a basic vector describing movement relative to the player character, like 1, 0, -1 for example. I find it better for code that’s already being run every frame, and it allows more simple calculations should they be needed.
Since you need this on the server, your best bet would be MoveDirection
. If they aren’t moving at all, the MoveDirection
will be 0, 0, 0, or just Vector3.zero
. If you find this works, make sure to mark @ronaldbox’s post as solution!
You also check when the player is running by using
Humanoid.Running:Connect(function(speed)
if speed > 1 then
print("Running")
end
end)
Or just use the MoveDirection suggested Above
uh hi so everyone was kinda the solution so i dont really know what to do but thank you all!