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!
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)
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)