How does this script work? I’ve had it laying around for a while and never understood how/why it worked.
repeat wait() until game.Players.LocalPlayer
m = game.Players.LocalPlayer:GetMouse()
m.KeyDown:connect(function(key)
if key == "0" then
print("Running")
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 20
end
end)
m.KeyUp:connect(function(key)
if key == "0" then
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 14
end
end)
What this script does is that it is a shift to sprint script, created by IronPhoenix_YT. As you can see, the script NEVER references shift.This was a LocalScript made to be in the StarterGUI.
EDIT: If shift is “0” then how do you find other key’s codes?
you can use user input service instead, like in the example below
local uis = game:GetService("UserInputService")
uis.InputBegan:Connect(function(input, gameProcessed)
--if gameProcessed then return end --/// if you are using keycodes like shift or others (esc, left shift, etc.) you can delete this, but it will also fire if player is typing
--
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.LeftShift then
print("left shift pressed!")
end
end
end)
put it into a local script (in starter gui or starter player scripts)
for holding and not holding use
local uis = game:GetService("UserInputService")
uis.InputBegan:Connect(function(input, gameProcessed)
--if gameProcessed then return end --/// if you are using keycodes like shift or others (esc, left shift, etc.) you can delete this, but it will also fire if player is typing
--
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.LeftShift then
print("left shift is now being holded")
end
end
end)
uis.InputEnded:Connect(function(input, gameProcessed)
--if gameProcessed then return end --/// if you are using keycodes like shift or others (esc, left shift, etc.) you can delete this, but it will also fire if player is typing
--
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.LeftShift then
print("left shift is now not being holded")
end
end
end)