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
01 | uif = game:GetService( "UserInputService" ) |
02 |
03 |
04 | uif.InputBegan:connect( function (imput) |
05 | if imput.KeyCode = = Enum.KeyCode.LeftShift then |
06 | local plr = game.Players.LocalPlayer |
07 | local char = script.Parent.Humanoid |
08 | char.WalkSpeed = 25 |
09 |
10 | wait( 3 ) |
11 |
12 | local char = script.Parent.Humanoid |
13 | char.Walkspeed = 16 |
14 | end |
15 | end ) |
I put a explanation by every error below for you to fix :) Mostly just made small mistakes.
01 | uif = game:GetService( "UserInputService" ) |
02 |
03 |
04 | uif.InputBegan:connect( function (imput) ---- :connect deprecated use :Connect |
05 | if imput.KeyCode = = Enum.KeyCode.LeftShift then |
06 | local plr = game.Players.LocalPlayer |
07 | local char = script.Parent.Humanoid |
08 | char.WalkSpeed = 25 |
09 |
10 | wait( 3 ) |
11 | ---------------------No Need---------------------------------- |
12 | local char = script.Parent.Humanoid |
13 | -------------------------------------------------------------------- |
14 | char.Walkspeed = 16 ----- WalkSpeed not Walkspeed |
15 | end |
16 | 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.
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
01 | uif = game:GetService( "UserInputService" ) |
02 | local player = game.Players.LocalPlayer |
03 | local char = player.Character.Humanoid |
04 |
05 | uif.InputBegan:Connect( function (imput) |
06 | if imput.KeyCode = = Enum.KeyCode.LeftShift then |
07 |
08 | char.WalkSpeed = 25 |
09 |
10 | wait( 3 ) |
11 |
12 | char.WalkSpeed = 16 |
13 | end |
14 | end ) |
thx for reading
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.
01 | uif = game:GetService( "UserInputService" ) |
02 |
03 |
04 | uif.InputBegan:connect( function (imput) |
05 | if imput.KeyCode = = Enum.KeyCode.LeftShift then |
06 | local plr = game.Players.LocalPlayer |
07 | local char = script.Parent.Humanoid |
08 | char.WalkSpeed = 25 |
09 |
10 | wait( 3 ) |
11 |
12 |
13 | char.WalkSpeed = 16 |
14 | end |
15 | end ) |
EDIT: Also, as others have said, you do not need to define char twice, once is sufficient.
You spelt WalkSpeed wrong, Speed has a Captial S. Also consider using :IsKeyDown()
for a Shift Boost
1 | UserInputService.InputBegan:Connect( function () |
2 | if (UserInputService:IsKeyDown(Enum.KeyCode.LeftShift)) then |
3 | --// Whatever happens here |
4 | end |
5 | end ) |