Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why wont the animation play when i press shift?

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

✓ Accepted answer

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.

3 comments

0

Its fine, i have someone making a script but il go ahead and accept your answer :)

0

I recommend that you learn how to script.

0

I recommend that you learn how to script.

This discussion is preserved as it was. New answers, comments, and votes are closed.