Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why wont the animation play when i press shift?

Asked by 6 years ago

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)

1 answer

Log in to vote
4
Answered by 6 years ago

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.

0
Its fine, i have someone making a script but il go ahead and accept your answer :) KinqAustinn 293 — 6y
0
I recommend that you learn how to script. hiimgoodpack 2009 — 6y
0
I recommend that you learn how to script. hiimgoodpack 2009 — 6y
Ad

Answer this question