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

Press Shift to run doesnt work!?

player = game.Players.LocalPlayer
mouse = player:GetMouse()

mouse.KeyDown:connect(function(key)
if key == "48" then
player.Character.Humanoid.WalkSpeed = 25
	end
end)

mouse.KeyUp:connect(function(key)
if key == "48" then
player.Character.Humanoid.WalkSpeed = 16
	end
end)

--doesnt work, please help!

1 comment

0

Put the localscript into 'StarterGui' and make the script a localscript.

3 answers

I don't see anything in particular wrong with your script thare, except maybe efficiency.. but here's another method for doing this. Using UserInputService, with the InputBegan, and InputEnded event will work as well, if not better.

Example;

local input = game:GetService("UserInputService")
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()

input.InputBegan:connect(function(key)
	if key == Enum.KeyCode.LeftShift then
		plr.Character.Humanoid.WalkSpeed = 36
	end
end)

input.InputEnded:conect(function(key)
	if key == Enum.KeyCode.LeftShift then
		plr.Character.Humanoid.WalkSpeed = 16
	end
end)

2 comments

0

I know this is very old but thanks, this helped me out a lot

0

You are welcome, I hope you are still learning becoming better! Happy developing!

You need to convert key to a byte.

key = key:byte()

You also need to change the strings to just numbers. Or you can use UserInputService (see other answer by Goulstem)

-- Put In StarterGui -- By JasonkaranikYoutube

local player = game.Players.LocalPlayer 
local mouse = player:GetMouse()

mouse.KeyDown:Connect(function(key)
	if key:lower() == string.char(48) then
		local hum = game.Players.LocalPlayer.Character.Humanoid
		if hum then
			 hum.WalkSpeed = 500
		end
	end
end)

mouse.KeyUp:Connect(function(key)
	if key:lower() == string.char(48) then
		local hum = game.Players.LocalPlayer.Character.Humanoid
		if hum then
			 hum.WalkSpeed = 16
		end
	end
end)

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