Shift to run script input error

I have a problem with a shift to run script with an animation I saw on a tutorial which is damaging my gameplay and I want to know if someone could help me.

When I press the shift key in my game, I can run until I try to press a tool (with numbers) which I do not want it to do. I have noticed the normal walk key doesnt do that.

This is the script:

local UIS = game:GetService('UserInputService')
local Player = game.Players.LocalPlayer
local Character = Player.Character


UIS.InputBegan:connect(function(input)
 if input.KeyCode == Enum.KeyCode.LeftShift then
  Character.Humanoid.WalkSpeed = 24
  local Anim = Instance.new('Animation')
  Anim.AnimationId = 'rbxassetid://9407047449'
  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)

Are you receiving any errors? If not, your keyboard most likely doesn’t support the combination of buttons you’re pressing down.

I’ve went ahead and improved the script a little bit. ‘:LoadAnimation’ is deprecated, but right now I don’t feel like replacing it.

local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Character = Player.Character

local Anim = Instance.new("Animation")
Anim.AnimationId = "rbxassetid://9407047449"
local PlayAnim = Character.Humanoid:LoadAnimation(Anim)

UIS.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.LeftShift then
			Character.Humanoid.WalkSpeed = 24
			PlayAnim:Play()
		end
	end
end)

UIS.InputEnded:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.LeftShift then
			Character.Humanoid.WalkSpeed = 16
			PlayAnim:Stop()
		end
	end
end)

2 Likes