So me and a friend are working on a game and he made a sprinting animation and we cant get it to work and dont know why, so when you press shift we want it to play the animation but it dont please help!
local Player = game.Players.LocalPlayer local Character = Player.Character or Player.CharacterAdded:Wait() local Human = Character:WaitForChild("Humanoid") local Mouse = Player:GetMouse() local Sprinting = false local SprintingANIM = script.Sprinting local SprintingANIM_Play = Human:LoadAnimation(SprintingANIM) Mouse.KeyDown:connect(function(key) if key:byte() == 48 then print'Shift down' SprintingANIM_Play:Play() --game.Players.LocalPlayer.Character.NewAnimate.run.RunAnim.AnimationId = 750586462 --game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 23 end end) Mouse.KeyUp:connect(function(key) if key:byte() == 48 then print'Shift up' SprintingANIM_Play:Stop() --game.Players.LocalPlayer.Character.NewAnimate.run.RunAnim.AnimationId = 896397665 --game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16 end end)
Im pretty sure using the mouse to get a keyboard key does not work. You could use the UserInputService.
--LocalScript game:GetService("UserInputService").InputBegan:connect(function(key) if key.KeyCode == Enum.KeyCode.LeftShift or key.KeyCode == Enum.KeyCode.RightShift then print("Shift down") --Im not very good with animations, so just do whatever you do to play animations. game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 23 end end) game:GetService("UserInputService").InputBegan:connect(function(key) if key.KeyCode == Enum.KeyCode.LeftShift or key.KeyCode == Enum.KeyCode.RightShift then print("Shift up") --Do whatever you need to do to stop animations. game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16 end end)
If you would like to use a byte value, you can just do key.KeyCode.Value
.