I'm trying to make a script that makes you walk faster every time you press "w" but I can't get it to work.
local Player = game.Players.LocalPlayer game.Players.LocalPlayer:GetMouse().KeyDown:connect(function(key) if string.lower(key) == "w" then Human = game.Workspace:FindFirstChild(Player) Human.Humanoid.Walkspeed = Human.Humanoid.Walkspeed + 5 end end)
ANY help is appreciated :D
Your problem is that you didn't capitolize the 's' in 'Walkspeed'. It should be 'WalkSpeed'.
You're also doing some things inefficiently.
1) You should make a variable
for the mouse, then use the event off of that variable. It makes the readability of your code much better.
2) You should access the Humanoid
through the Player's Character.
3) You shouldn't add the WalkSpeed, because then if they spam the 'w' button then they can get like 500 WalkSpeed. Instead, set the WalkSpeed to the original(16) plus five, so 21.
Also, you should make a KeyUp event, with the letter, to reset the walkspeed back to normal so they don't run forever after they press the button once.
local plr = game.Players.LocalPlayer local mouse = plr:GetMouse local extraSpeed = 21 local regSpeed = 16 mouse.KeyDown:connect(function(key) if key:lower() == "w" and plr.Character then local hum = plr.Character:FindFirstChild('Humanoid') if hum then hum.WalkSpeed = extraSpeed end end end) mouse.KeyUp:connect(function(key) if key:lower() == "w" and plr.Character then local hum = plr.Character:FindFirstChild('Humanoid') if hum then hum.WalkSpeed = regSpeed end end end)
For what you are doing, the neatest way to go about this is to perhaps use ContextActionService:
plr = game.Players.LocalPlayer or game.Players.LocalPlayer:wait() chr = plr.Character or plr.Character:wait() context = game:GetService("ContextActionService") context:BindActionToInputTypes( "walkspeedIncrease", function() chr.Humanoid.Walkspeed = chr.Humanoid.WalkSpeed + 5 end, true, Enum.KeyCode.W )
The line ** Human = game.Workspace:FindFirstChild(Player)** is wrong. You should replace that with:
Player.Character