The issue could be with how the game.ReplicatedStorage.Minutes.Value is being updated. Based on the code provided, it seems that the initial value of game.ReplicatedStorage.Minutes.Value is 2.
When the event is fired, the value of game.ReplicatedStorage.Minutes.Value is increased by 5 to 7. However, since the code is inside a loop that waits for 10 seconds before setting the done variable back to false , the loop runs 5 times (50 seconds) before the done variable is reset. During this time, any further updates to game.ReplicatedStorage.Minutes.Value will continue to increase the value.
Therefore, if any other events or updates are happening that are increasing the game.ReplicatedStorage.Minutes.Value during this 50 second period, it could cause the value to exceed 60 (which is causing it to wrap around to 0 and continue counting up).
To fix this, you could either ensure that the event only fires once, or update the code to not rely on the done variable to limit the event to only firing once. Additionally, you could consider using a while loop instead of a wait statement to better control the timing of the event.
If the event is only firing once, the issue is likely caused by another part of your code that is updating the game.ReplicatedStorage.Minutes.Value variable.
Based on the code you provided, it looks like the game.ReplicatedStorage.Minutes.Value variable is being increased by 5 every time the Boosts.Extratime2 event is fired. However, if there is other code running that also updates this variable, it could cause unexpected behavior.
You could try adding print statements to any other code that updates game.ReplicatedStorage.Minutes.Value to see if it’s being updated unintentionally. Additionally, you could consider adding a check to ensure that game.ReplicatedStorage.Minutes.Value never exceeds 60 to prevent it from wrapping around to 0 and counting up. For example:
game.ReplicatedStorage.Events.Boosts.Extratime2.OnServerEvent:Connect(function(player)
if done == false then
print("Extra Time fired")
done = true
player:FindFirstChild("ExtrasBought").Value -= 1
game.ReplicatedStorage.Minutes.Value = math.min(game.ReplicatedStorage.Minutes.Value + 5, 60) -- update the minutes value and ensure it doesn't exceed 60
wait(10)
done = false
end
end)
This will ensure that the game.ReplicatedStorage.Minutes.Value variable is never increased beyond 60, preventing it from wrapping around to 0 and counting up.
extra.MouseButton1Click:Connect(function()
if lplr:FindFirstChild("ExtraTimeBought").Value == 0 then
game.ReplicatedStorage.Events.Boosts.Extratime2:FireServer()
else
return
end
end)
I will try this, I did just discover there is another script causing this, as I set this script to all comments, so that it would not do anything, but it still went from 2 to 79 now.
Only a serverscript and a localscript. The serverscript is the one I disabled, so that cannot be it and localscripts cant change values. It does not give any error message btw.
I suggest to do the local script. Use this script as well.
Check the out put, there should be a print with “2” and another right after with a different number
local repl = game:GetService("ReplicatedStorage")
repl.Events.Boosts.Extratime2.OnServerEvent:Connect(function(player)
if done == false then
print("Extra Time fired")
done = true
player:FindFirstChild("ExtrasBought").Value -= 1
print(repl.Minutes.Value)
repl.Minutes.Value += 5 --try repl.Minutes = repl.Minutes + 5
print(repl.Minutes.Value)
task.wait(10)
done = false
end