Help With MoveDirection

So my question is that the movement direction is not detecting the player’s movement and the “iswalking” value doesn’t change. btw, there is no error output or “player is moving” output.

Anyone can help me to solve this?

Here’s the code

--Value
local RunService = game:GetService("RunService")
local UIS = game:GetService("UserInputService")

local playerModel = script.Parent
local humanoid = playerModel:WaitForChild("Humanoid")
local plr = game.Players.LocalPlayer

local stamina = Instance.new("Folder", plr)
stamina.Name = "Stamina"

local staminavalue = Instance.new("IntValue", stamina)
staminavalue.Name = "Stamina"
staminavalue.Value = 100

local iswalking = Instance.new("BoolValue", stamina)
iswalking.Name = "IsWalking"
iswalking.Value = false


local isrunning = Instance.new("BoolValue", stamina)
isrunning.Name = "IsRunning"
isrunning.Value = false

--Script
if humanoid.MoveDirection == Vector3.new(0,0,0) then
	iswalking = true
	print("player is moving")
elseif humanoid.MoveDirection ~= Vector3.new(0,0,0) then
	iswalking = false
	print("player is not moving")
end

image
im walking now

1 Like

Look at this line

i guess you should to have there iswalking.Value = false

Also you are doing your check only once that’s why you should to loop it or change it when humanoid move direction changes

1 Like

You can detect if the player is moving or not by using the humanoid.MoveDirection.Magnitude property:

local players = game:GetService("Players")

players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local humanoid = character:WaitForChild("Humanoid")

		humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
			if humanoid.MoveDirection.Magnitude > 0 then
				print("Player is moving!")
			else
				print("Player is not moving!")
			end
		end)
	end)
end)
2 Likes

Here look at this part:

if huma	noid.MoveDirection == Vector3.new(0,0,0) then
		iswalking = true
		print("player is moving")
	elseif humanoid.MoveDirection ~= Vector3.new(0,0,0) then
		iswalking = false
		print("player is not moving")
	end

See? You are only checking it once. It should be

while task.wait() do
	if humanoid.MoveDirection == Vector3.new(0,0,0) then
		iswalking.Value = true
		print("player is moving")
	elseif humanoid.MoveDirection ~= Vector3.new(0,0,0) then
		iswalking.Value = false
		print("player is not moving")
	end
end

Also, like what kercig said, you forgot to put “.Value” when setting the value.

Optimized Version
while task.wait() do
	iswalking.Value = not humanoid.MoveDirection == Vector3.new(0,0,0)
	print(iswalking.Value)
end
3 Likes

thx so much @kercig but @calvin_coco did what exactly I want.

1 Like

thx so much @0stonze but @calvin_coco did what exactly I want.

1 Like