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

Does using the phrase Variable = Variable + 1 make it increase by 1?

Asked by 7 years ago

Please encode Lua code in the Lua block code tag (look for the Lua icon in the editor).

This should cause the WalkSpeed of the players to increase by 1 everytime "R" is pressed.

It doesn't work

Player = game.Players.LocalPlayer Character = Player.Character Humanoid = Character.Humanoid WalkSpeed = Humanoid.WalkSpeed

game:GetService("UserInputService").InputBegan:connect(function(LetsSee) if LetsSee.KeyCode == Enum.KeyCode.R then print("R was pressed") WalkSpeed = WalkSpeed + 1 end end)

1 answer

Log in to vote
0
Answered by
Link150 1355 Badge of Merit Moderation Voter
7 years ago
Edited 7 years ago

This is because you are incrementing the value of your WalkSpeed variable, and not the WalkSpeed property of the player character's Humanoid object. WalkSpeed and Character.Humanoid.WalkSpeed are two different variables.

0
I made WalkSpeed = Humanoid.WalkSpeed, Humanoid = Character.Humanoid, Character = Player.Character, Player = game.Players.LocalPlayer dakanji123 97 — 7y
0
So WalkSpeed = game.Players.LocalPlayer.Character.Humanoid.WalkSpeed dakanji123 97 — 7y
0
Yes, but "Walkspeed" alone is a separate variable from "Humanoid.Walkspeed". Link150 1355 — 7y
0
To be more specific, variable "WalkSpeed" is set to the player's WalkSpeed value, and not the value itself. TheeDeathCaster 2368 — 7y
Ad

Answer this question