Why is this run script not working?

so basically this local script under starterplayerscripts is suppose to make the player run when they press leftcontrol but for some reason its not working and i cant seem to find out why?

local players = game:GetService("Players")
local locpl = players.LocalPlayer
local UserInputServer = game:GetService("UserInputService")
local humanoid = locpl.Character:FindFirstChild("Humanoid") 
local Ranimation = game.StarterPlayer.StarterCharacterScripts.RUN.RunAnim
local playit = humanoid:LoadAnimation(Ranimation)


UserInputServer.InputBegan:Connect(function(input)
	if input == Enum.KeyCode.LeftControl then
		if locpl.Character:FindFirstChild("Humanoid") then
			locpl.Character:FindFirstChild("Humanoid").WalkSpeed = 30
			playit:Play()
		end
	end
end)

UserInputServer.InputEnded:Connect(function()
	locpl.Character:FindFirstChild("Humanoid").WalkSpeed = 16
	playit:Stop()
end)

This needs to be input.KeyCode == Enum.KeyCode.LeftControl instead. Additionally, you should edit the input ended function to make sure the input is also LeftControl so that when releasing a different key, it doesn’t stop the running.

2 Likes

wym by " this needs to be “input.KeyCode == Enum.KeyCode.LeftControl` instead.”

you want me to replace " if input == Enum.KeyCode.LeftControl then" to that?

local players = game:GetService("Players")
local locpl = players.LocalPlayer
local UserInputServer = game:GetService("UserInputService")
local humanoid = locpl.Character:FindFirstChild("Humanoid") 
local Ranimation = game.StarterPlayer.StarterCharacterScripts.RUN.RunAnim
local playit = humanoid:LoadAnimation(Ranimation)


UserInputServer.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftControl then
		if locpl.Character:FindFirstChild("Humanoid") then
			locpl.Character:FindFirstChild("Humanoid").WalkSpeed = 30
			playit:Play()
		end
	end
end)

UserInputServer.InputEnded:Connect(function()
	locpl.Character:FindFirstChild("Humanoid").WalkSpeed = 16
	playit:Stop()
end)

This should work

oh yeah didnt notice it alr il try it thanks

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.