The error you're getting is because you're getting the Character incorrectly. You don't need to get the player's children to get the character because the character isn't a child of the player, it's a property that contains a reference to the character model which is parented to the workspace. So, you can just do Player.Character.
Also, your code is not going to work properly because your if statement is outside of the loop and is not being constantly checked by anything. Also, because you have a while loop, it's never actually going to get to the if statement because it's looping indefinitely.
You don't need a while loop for this though, you can use the function GetPropertyChangedSignal to detect when the MoveDirection property has changed. This is a lot better way of doing this because it won't constantly use resources when nothing is being changed.
I also find Attributes to be very helpful in these types of situations because attributes, unlike variables, you can detect when a specific attribute has changed by using the function GetAttributeChangedSignal.
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local VectorZero = Vector3.new(0, 0, 0)
Character:GetAttributeChangedSignal("Walking"):Connect(function()
if Character:GetAttribute("Walking") then
print("Player is walking")
else
print("Player has stopped")
end
end)
Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
if Humanoid.MoveDirection ~= Vector3.new(0,0,0) then
Character:SetAttribute("Walking", true)
else
Character:SetAttribute("Walking", false)
end
end)
You could also try using the Humanoid.Running event which does exactly the same as the code above. This event has a parameter which is the speed the character is moving at, which you could use to detect when they're standing still, running, etc...
Example
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
Humanoid.Running:Connect(function(Speed)
if Speed > 0 then
print("Player is moving")
else
print("Player has stopped")
end
end)