###The problem lies in the fact that you wrongly assume that the 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.
local Client = game.Players.LocalPlayer
local Character = Client.Character or Client.CharacterAdded:Wait()
local Humanoid = Character.Humanoid
while true do
Humanoid.WalkSpeed = Humanoid.WalkSpeed + 0.5
wait(0.5)
print(Humanoid.WalkSpeed)
end
###It is important to note the difference between a reference and a value. You can think of a reference as holding an actual memory location whilst a value just holds normal information (for example, a boolean). In Lua, for example, dictionaries are passed by reference.
local t1 = {
foo = "abc",
bar = 123,
foobar = true
}
local t2 = {
foo = "abc",
bar = 123,
foobar = true
}
local t1reference = t1
t1.foo = "Hello world!"
print(t1.foo)
print(t1reference.foo)
print(t2.foo)
###The t1 and t1reference variables both hold the same exact dictionary whilst t2 is a different dictionary even though it holds the same values.
###However, data like booleans and numbers are passed via value.
local number = 50
local numberVal = num
number = 25
print(number)
print(numberValue)
local bool1 = false
local bool1Val = bool1
bool1 = true
print(bool1)
print(bool1Val)
###Even though 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.
2 comments
#speed simulator 10
what