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

Im trying to make a script that makes u faster when u press left shift but how?

UserInputService = game:GetService("UserInputService") local players = game.Players.LocalPlayer

local LeftShiftPressed = false

UserInputService.InputBegan:Connect(function(input,gameProccesedEvent) if input.KeyCode == Enum.KeyCode.LeftShift then LeftShiftPressed = true if players:FindFirstChild("Humanoid") then players.Humanoid.CharacterWalkSpeed = 90

		UserInputService.InputBegan:Connect(function(input,gameProccesedEvent)
			if input.KeyCode == Enum.KeyCode.LeftShift then
				LeftShiftPressed = false
				if players:FindFirstChild("Humanoid") then
					players.Humanoid.CharacterWalkSpeed = 16
	end
end

end)

		while LeftShiftPressed == true do
			wait()
			players.Humanoid.CharacterWalkSpeed = 90
		end

6 comments

0

You have the code so what exactly do u need. Is your code not working?

0

yes

0

it do not work

0

Can I see the variable for players?

0

/?

0

its at the beggining where it says game.Players.LocalPlayer

1 answer

So your not actually grabbing the player's character where the humanoid is. Instead of doing players:FindFirstChild("Humanoid"), create a variable for the character and replace players with it.

local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

UserInputService.InputBegan:Connect(function(input,gameProcessed)
	--if not gameProcessed then
		if input.KeyCode == Enum.KeyCode.LeftShift then
	                if players:FindFirstChild("Humanoid") then
	                    players.Humanoid.CharacterWalkSpeed = 90
			end
		end
	--end
end

Also, instead of using a loop to check if the player is sprinting, use the InputEnded function.

UserInputService.InputEnded:Connect(function(input,gameProcessed)
	--if not gameProcessed then
		if input.KeyCode == Enum.KeyCode.LeftShift then
	                if players:FindFirstChild("Humanoid") then
	                    players.Humanoid.CharacterWalkSpeed = 16
			end
		end
	--end
end

if you want the player to sprint while using chat, keep the gameprocessed and the end that goes with it commented. If you do uncomment them, the player won't be able to sprint while using shift-lock.

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