I've been trying to figure out how to make it so while a player is moving/running forwards, every 0.5 seconds their walkspeed will increase by 0.5. I keep on trying to figure out how to do it and when I do think I've got it, I test and it doesn't work. I've tried using the Roblox wiki, and other sites, but I can't find anything remotely similar on HOW to do this. If you can/do respond, can you explain how to do it, in a sort of tutorial fashion, so I can try to understand it more? EDIT: Here's my most recent attempt. The code doesn't give any errors, but it just doesn't change the player's walkspeed.
PlayerSpeed = game.Players.LocalPlayer.Character.Humanoid.WalkSpeed while true do PlayerSpeed = PlayerSpeed + 0.5 wait(0.5) print(PlayerSpeed) end
EDIT 2: For more info, I'm placing the script in "StarterPack". I'm not sure if that's the right place.
PlayerSpeed
variable is a reference to the actual property of the Humanoid
. If the walk speed of the Humanoid
changes, the variables you have defined won't update; only its WalkSpeed
property will change. In order to fix this, you can remove the PlayerSpeed
variable and only make direct accesses to the WalkSpeed
property of the Humanoid
. You could also modify the variables to hold the Humanoid
object itself.-- Global variables are bad practice. Put 'local' in front of your variables when defining them. local Client = game.Players.LocalPlayer local Character = Client.Character or Client.CharacterAdded:Wait() -- The character does not instantly load. We must compensate for this. local Humanoid = Character.Humanoid while true do Humanoid.WalkSpeed = Humanoid.WalkSpeed + 0.5 wait(0.5) print(Humanoid.WalkSpeed) end
local t1 = { foo = "abc", bar = 123, foobar = true } local t2 = { foo = "abc", bar = 123, foobar = true } local t1reference = t1 --t1 & t1reference are the same dictionary now, but t2 is different t1.foo = "Hello world!" print(t1.foo) --> Hello world! print(t1reference.foo) --> Hello world! print(t2.foo) --> abc
t1
and t1reference
variables both hold the same exact dictionary whilst t2
is a different dictionary even though it holds the same values.local number = 50 local numberVal = num number = 25 print(number) --> 25 print(numberValue) --> 50 local bool1 = false local bool1Val = bool1 bool1 = true print(bool1) --> true print(bool1Val) --> false
numberValue
was set to number
, both variables have different memory and so changing one value does not change the other value. Same for the boolean values, bool1Val
never changed even after updating bool1
.