So i got a run script that displays a run animation and i dont know how to make it play a sound. how do i make it play the sound when you run? what i got so far is ~~~~~~~~~~~~~~~~~
local Player = game.Players.LocalPlayer local Character = workspace:WaitForChild(Player.Name) local Humanoid = Character:WaitForChild('Humanoid') local RunAnimation = Instance.new('Animation') RunAnimation.AnimationId = 'rbxassetid://2543615157' RAnimation = Humanoid:LoadAnimation(RunAnimation) Running = false function Handler(BindName, InputState) if InputState == Enum.UserInputState.Begin and BindName == 'RunBind' then Running = true Humanoid.WalkSpeed = 70 elseif InputState == Enum.UserInputState.End and BindName == 'RunBind' then Running = false if RAnimation.IsPlaying then RAnimation:Stop() end Humanoid.WalkSpeed = 16 sound:Stop() end end Humanoid.Running:connect(function(Speed) if Speed >= 10 and Running and not RAnimation.IsPlaying then RAnimation:Play() Humanoid.WalkSpeed = 70 sound:Play() elseif Speed >= 10 and not Running and RAnimation.IsPlaying then RAnimation:Stop() Humanoid.WalkSpeed = 16 sound:Stop() elseif Speed < 10 and RAnimation.IsPlaying then RAnimation:Stop() Humanoid.WalkSpeed = 16 sound:Stop() end end) Humanoid.Changed:connect(function() if Humanoid.Jump and RAnimation.IsPlaying then RAnimation:Stop() end end) game:GetService('ContextActionService'):BindAction('RunBind', Handler, true, Enum.KeyCode.LeftShift)
~~~~~~~~~~~~~~~~~
Hi superpichufan_57,
You might want to try using GetPropertyChangedSignal("MoveDirection")
With this you can check how fast the character is moving and act accordingly
Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function() if humanoid.MoveDirection.Magnitude > 0 then -- if they are moving if sound.IsPlaying == false then -- if it isn't already playing sound:Play() end else sound:Stop() end end)
Of course you could tailor this to your specific situation. Let me know if this helps.