✓ Accepted answer
If all you want to do is change the walking animation for the character. Use the existing Animate script located in the character when they spawn. You can replace objects simply by using the CharacterAdded event (I mention how to use events in this answer if you do not know how).
You almost have it. Whoever, events are not booleans, you can't compare them to true or false (the comparison will always compute to being false).
Think of an event as another object that does not show up in the Explorer. It has some methods and a property. The ones you need here are the connect and wait method (not uppercase names).
To check when the player is running, you need to use the connect method of the Running event and give it a function (which it will run when the humanoid starts running with the speed as a parameter).
Here is an example:
local function onRunning()
print"running"
end
script.Parent.Humanoid.Running:connect(onRunning)
With this in mind, you can also stop the animation later using the same function:
local function onRunning(speed)
if speed > 0 and animTrack.IsPlaying == false then
while true do
local _, newState = script.Parent.Humanoid.StateChanged :wait()
if newState ~= Enum.HumanoidStateType.Running then
break
end
end
end
end
Edit Tried to make my explenation clearer and changed ChangeState to StateChanged (ChangeState is not an event).
1 comment
I have already tried to use the script that is the charector when you spawn but it won't work since my animation is for an advance model.