I want to be able to have this play the animation when the humanoid walks but i'm not sure where else to go with this script to make it work any help?
local animation = Instance.new("Animation") animation.AnimationId = "http://www.roblox.com/Asset?ID=397144835" local animController = Instance.new("AnimationController") animController.Parent = script.Parent local animTrack = animController:LoadAnimation(animation) if script.Parent.Humanoid.Running == true then while true do --I'm having most trouble here animTrack:Play() wait(1) if script.Parent.Humanoid.Running == false then animTrack:Stop() end end end
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 -- Play the animation. -- Then you can use a loop combined with the StateChanged event's wait method to check when the user stops running. -- Here is an example (wait, does exactly what it says, it waits for the event to be fired and returns the results): while true do local _, newState = script.Parent.Humanoid.StateChanged :wait() -- Discard the first result (we only need the new state) if newState ~= Enum.HumanoidStateType.Running then break -- Stop the loop so the animation can be stopped. end end -- Stop the animation. end end
Edit Tried to make my explenation clearer and changed ChangeState to StateChanged (ChangeState is not an event).