Set an animated image based if the player is moving

Greetings!

Here’s my current code.

local humanoid = script.Parent.Parent.Humanoid

while wait() do
if humanoid.MoveDirection.Magnitude == 0 then
print(“yesyes”)
script.Parent.Decal.Texture = “rbxassetid://rbxassetid://5813744553”
wait(0.5)
script.Parent.Decal.Texture = “rbxassetid://5813736561”
wait(0.5)
script.Parent.Decal.Texture = “rbxassetid://5813744107”
wait(0.5)
script.Parent.Decal.Texture = “rbxassetid://5813736561”
wait(0.5)
end
end

Nothing happens when I do this code. No errors ether. Thank you!

Is it a ui or workspace part…

Its a script on a part which is welded to the player.

There is a Humanoid property called “running” humanoid.Running:Connect(function() print("yesyes") end)

I used it in a script of mine, I found it out by taking a look at the default animation script in the character.

So what do you suggest I do? Sorry, Im a bit confused. :3

You use the running property, i will even rewrite your whole script for you:

`local humanoid = script.Parent.Parent.Humanoid

humanoid.Running:Connect(function(speed)
if speed ~= 0 then
print(“yesyes”)
script.Parent.Decal.Texture = “rbxassetid://rbxassetid://5813744553”
wait(0.5)
script.Parent.Decal.Texture = “rbxassetid://5813736561”
wait(0.5)
script.Parent.Decal.Texture = “rbxassetid://5813744107”
wait(0.5)
script.Parent.Decal.Texture = “rbxassetid://5813736561”
wait(0.5)
end
end)`

1 Like

Thats odd. Im not receiving the print. And it’s not playing the images/errors. Is there an issue with the humanoid maybe?

Let me test out the script for myself, I will get back to you once i determine the problem

Alright, Thank you!
(Char Limit)

Okay, I fixed it. The problem was the speed argument, that is unnecessary. Aswell as you were defining the path to the humanoid wrong. If the script is in StarterCharacter (which i assume it is and if it is not you should put it there and remake the path to the brick) then the path to the humanoid is simply “script.Parent.Humanoid”

`local humanoid = script.Parent.Humanoid

humanoid.Running:Connect(function()

print(“yesyes”)
script.Parent.Decal.Texture = “rbxassetid://rbxassetid://5813744553”
wait(0.5)
script.Parent.Decal.Texture = “rbxassetid://5813736561”
wait(0.5)
script.Parent.Decal.Texture = “rbxassetid://5813744107”
wait(0.5)
script.Parent.Decal.Texture = “rbxassetid://5813736561”
wait(0.5)

end)`

2 Likes

Thank you! Is there a way for this to only run while you are walking?

humanoid.Running goes for all character speeds.

humanoid.Running:Connect(function(speed)
   if speed > 0 then
   --code
    else   
  end 
end)

This is my real question.
Is there a way to have a loop and then break it randomly? For example, when you start running It starts the loop, but when you go idle it stops and breaks the loop.

Let me know if this helps.

humanoid.Running:Connect(function(speed)
   if speed == 0 then
   break
    else   
  end 
end)

(Break statement must be inside of a loop.)

Oh right, this isn’t a loop. My bad.

Is there anyway you can reproduce your script and put a loop in it? such as while true do or while wait do

I could do that. : D
(Chars. :DDDDDDD

That’s great, be a lot easier.