Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

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

Asked by 6 years ago

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) 
0
Where is this script located? Thetacah 712 — 6y
0
For this to work, this script must be located in the players character(which is located in the workspace). Thetacah 712 — 6y
0
you defined char twice, dont do that. DinozCreates 1070 — 6y
0
u have 5 answers accept one WideSteal321 773 — 6y

5 answers

Log in to vote
0
Answered by 6 years ago

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)


Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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.

0
Oof. DinozCreates 1070 — 6y
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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

0
char is defined after its use? GoldAngelInDisguise 297 — 6y
0
omg hacker WideSteal321 773 — 6y
0
Using the `local` keyword twice on the same variable is valid. ee0w 458 — 6y
0
ok we geddit errors are made WideSteal321 773 — 6y
Log in to vote
0
Answered by
Thetacah 712 Moderation Voter
6 years ago
Edited 6 years ago

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.

0
line 12 DinozCreates 1070 — 6y
0
dude u copy WideSteal321 773 — 6y
0
Redefining "Char" twice will not result in an error.. Thetacah 712 — 6y
0
**cough** my answer is almost the same and I answered first. WideSteal321 773 — 6y
0
thanks Averted_Vision 177 — 6y
Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
6 years ago

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)
0
Also use :Connect() Ziffixture 6913 — 6y
0
Don't use :IsKetDown() stick with InputBegan RoButCantBlox 68 — 6y
0
Actually yes, use it, you can, nothing happens anyway Ziffixture 6913 — 6y

Answer this question