When I play the game and I hold shift to run, the animation works normally. But when I stop moving and hold shift it plays the animation even without me walking. I want to compare my script with Mortem Metallum running. When you hold shift and stop, it stops the animation.
here is video evidence: https://imgur.com/a/gDtKdwc
here is the script:
local UIS = game:GetService('UserInputService') local Player = game.Players.LocalPlayer local Character = Player.Character UIS.InputBegan:connect(function(input)--When a player has pressed LeftShift it will play the animation and it will set the normal walking speed (16) to 35. if input.KeyCode == Enum.KeyCode.LeftShift then Character.Humanoid.WalkSpeed = 35 local Anim = Instance.new('Animation') Anim.AnimationId = 'rbxassetid://myid' --i put this here because this my id, not yours to steal. PlayAnim = Character.Humanoid:LoadAnimation(Anim) PlayAnim:Play() end end) UIS.InputEnded:connect(function(input) if input.KeyCode == Enum.KeyCode.LeftShift then Character.Humanoid.WalkSpeed = 16 PlayAnim:Stop() end end)
here you go. hope this is what you wanted.
local UIS = game:GetService('UserInputService') local Player = game.Players.LocalPlayer local Character = game.Workspace:WaitForChild(Player.Name) local running = false -- this isn't technically "needed" but I used it as a way to avoid checking the Character.Humanoid.WalkSpeed = 35. UIS.InputBegan:connect(function(input) if input.KeyCode == Enum.KeyCode.LeftShift then if Character.Humanoid.MoveDirection.Magnitude > 0 then -- there was a bug in your script to where you could press shift without walking and the animation would play. that would look funny lol Character.Humanoid.WalkSpeed = 35 local Anim = Instance.new('Animation') Anim.AnimationId = 'rbxassetid://5054442658' -- if u want a laugh look at the animation i tested this with. You'll need to disable the character script animate inside of the character model PlayAnim = Character.Humanoid:LoadAnimation(Anim) PlayAnim:Play() running = true end end end) UIS.InputEnded:connect(function(input) if PlayAnim then -- because of the MoveDirection.Magnitude thing I added, if you pressed shift then the animation may not exist. if input.KeyCode == Enum.KeyCode.LeftShift then Character.Humanoid.WalkSpeed = 16 PlayAnim:Stop() -- this would throw an error so thats why the if PlayAnim running = false end end end) Character.Humanoid.Changed:Connect(function() if PlayAnim then -- same as above if Character.Humanoid.MoveDirection.Magnitude == 0 and running == true and PlayAnim.IsPlaying == true then -- here I'm checking to see if the character is not moving and if running is equal to true and if the animation is playing PlayAnim:Stop() -- if its playing and character aint moving we stop it end if Character.Humanoid.MoveDirection.Magnitude > 0 and running == true and PlayAnim.IsPlaying == false then -- if the character is still holding shift and decides to start running again by pressind w or whatever, then he can get his cool animation PlayAnim:Play() end end end)
well i spent 2 and a half hours learning about animations.