Whenever I try to do simple addition it just keeps the number the same as if I never added anything. I can verify that it is running the line of the script where I do the addition because I have a print immediately before it which prints when I run the script.
This is where the addition takes place:
print("recently rolled so increasing max distance") --Prints correctly
MaxDistance += 25 --Doesn't do anything but also has no errors
The entire loop this is happening in is:
while LoopActive == true do
wait(0.33)
local RootPart = Character:FindFirstChild("HumanoidRootPart")
if RootPart ~= nil then
if StaminaTable[Character.Name] ~= nil and StaminaTable[Character.Name].Stamina < 12 then
StaminaTable[Character.Name].Stamina += 1
PhysicalActionEvent:FireClient(Player, StaminaTable[Character.Name].Stamina)
end
if StaminaTable[Character.Name] ~= nil then
StaminaTable[Character.Name].CD = false
end
if DelayedPreviousPositions[Character.Name] ~= nil then
local PreviousPos = DelayedPreviousPositions[Character.Name]
PreviousPos = Vector3.new(PreviousPos.X, 0, PreviousPos.Z)
local MaxDistance = (Character.Humanoid.WalkSpeed * 0.33) + 4
local SeatPart = Character.Humanoid.SeatPart
if SeatPart ~= nil then
if SeatPart.ClassName == "VehicleSeat" then
MaxDistance = (SeatPart.MaxSpeed * 0.33) + 12
elseif SeatPart:IsDescendantOf(game.Workspace.Vehicles) ~= true then
MaxDistance = (SeatPart.Parent.VehicleSeat.MaxSpeed * 0.33) + 4
else
MaxDistance = 99999
end
elseif Player:FindFirstChild("RecentlyRolled") ~= nil and Player.RecentlyRolled.Value == true then
print("recently rolled so increasing max distance")
MaxDistance += 25 --This is the addition which isn't working
end
local Distance = (PreviousPos - Vector3.new(RootPart.Position.X, 0, RootPart.Position.Z)).Magnitude
if Distance > MaxDistance then
print(Distance, " was greater than ", MaxDistance)
RootPart.Position = DelayedPreviousPositions[Character.Name]
end
end
DelayedPreviousPositions[Character.Name] = RootPart.Position
end
end
I have tried replacing
MaxDistance += 25
with
MaxDistance = MaxDistance + 25
but that didn't fix anything.
The script runs completely without errors and all the prints print correctly, yet it seems as if it is incapable of addition in that one spot for some unknown reason.
UPDATE: This only happens sometimes, the majority of the time it is able to use the value with the addition, but occasionally it uses the old value (yes it is adding to the value I verified with prints)

8 comments
It's probably Luau just being special for no apparent reason. Use value = value + n.
tried that it didn't change anything
If you're not printing MaxDistance then you don't actually know if it changed. The code you're showing us has no instance of you doing this. Because the messages print you're only assuming the addition is being done. Nothing can be proved without actually printing the value.
I did print the value
look at line 31
One print isn't enough.
what do you mean? There would be no point in printing the same thing multiple times lol
Nevremind, I understand what you meant now and I put another print so I can get the value before additon, after the addition, and the value used after all the addition is done. I discovered that roughly 15% of the time the value used after the addition is the value pre-addition which makes no sense as it no longer exists. Even when this happens it still prints the post-addition value correctly.