✓ Accepted answer
**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)
1 comment
is there way to find if the character is moving or not?