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

can somebody help me fix my code for speed boost with a hotkey?

So basically I'm trying to make a short speed boost when you press shift but whenever I try the script it keeps saying Walkspeed is not a valid member of Humanoid can somebody review this code for me please, I suck at scripting and I'm like 2 days into it so don't criticize me too hard ;p

uif = game:GetService("UserInputService")


uif.InputBegan:connect(function(imput)
	if imput.KeyCode == Enum.KeyCode.LeftShift then
		local plr = game.Players.LocalPlayer
		local char = script.Parent.Humanoid
		char.WalkSpeed = 25
		
		wait(3)
		
		local char = script.Parent.Humanoid
		char.Walkspeed = 16
	end
end) 

4 comments

0

Where is this script located?

0

For this to work, this script must be located in the players character(which is located in the workspace).

0

you defined char twice, dont do that.

0

u have 5 answers accept one

5 answers

✓ Accepted answer

I put a explanation by every error below for you to fix :) Mostly just made small mistakes.

	uif = game:GetService("UserInputService")
	 
	 
	uif.InputBegan:connect(function(imput) ---- :connect deprecated use :Connect
	    if imput.KeyCode == Enum.KeyCode.LeftShift then
	        local plr = game.Players.LocalPlayer
	        local char = script.Parent.Humanoid
	        char.WalkSpeed = 25
	 
	        wait(3)
	 ---------------------No Need----------------------------------
	        local char = script.Parent.Humanoid
	--------------------------------------------------------------------
	        char.Walkspeed = 16 ----- WalkSpeed not Walkspeed
	    end
	end)


On Line 13 It Is Spelled "Walkspeed" When The Acutal Propety Is Called "WalkSpeed" With A Capital S. Its Okay If You Forget Something Like That We Were All New At One Point. From Now On Always Look At The Punctuation And Spelling. You Should Also Look At Scripting Tutorial Such As AlvinBlox Or Peasfactory Before You Start Making A Game.

1 comment

0

Oof.

You can say local char = twice but u don't need too. Also in the near future :connect() will not work. Use :Connect() and use WalkSpeed not Walkspeed. I have changed local char to my liking btw not much diffrent

uif = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local char = player.Character.Humanoid

uif.InputBegan:Connect(function(imput)
    if imput.KeyCode == Enum.KeyCode.LeftShift then
       
        char.WalkSpeed = 25

        wait(3)

        char.WalkSpeed = 16
    end
end) 

thx for reading

4 comments

0

char is defined after its use?

0

omg hacker

0

Using the local keyword twice on the same variable is valid.

0

ok we geddit errors are made

Hey,

Assuming this script is located in the players character(which is located in the workspace), you only made one small error.

That small error? Capitalization! On line 13, it should be WalkSpeed and not Walkspeed.

Furthermore, :connect is now depricated and :Connect should be used instead.

Cheers.

uif = game:GetService("UserInputService")


uif.InputBegan:connect(function(imput)
    if imput.KeyCode == Enum.KeyCode.LeftShift then
        local plr = game.Players.LocalPlayer
        local char = script.Parent.Humanoid
        char.WalkSpeed = 25

        wait(3)

 
        char.WalkSpeed = 16
    end
end) 

EDIT: Also, as others have said, you do not need to define char twice, once is sufficient.

5 comments

0

line 12

0

dude u copy

0

Redefining "Char" twice will not result in an error..

0

cough my answer is almost the same and I answered first.

0

thanks

You spelt WalkSpeed wrong, Speed has a Captial S. Also consider using :IsKeyDown() for a Shift Boost

UserInputService.InputBegan:Connect(function()
  if (UserInputService:IsKeyDown(Enum.KeyCode.LeftShift)) then
     --// Whatever happens here
  end
end)

3 comments

0

Also use :Connect()

0

Don't use :IsKetDown() stick with InputBegan

0

Actually yes, use it, you can, nothing happens anyway

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