I am trying to create a rebirth system but I am having some issues with it. After the rebirth is over 1 whenever any points are gained it adds an insane amount instead of adding the change in value. I added a print function to see what the change in value was and it printed a bunch of numbers instead of 1 all multiplied by 2. How do I fix this?
game.ReplicatedStorage.RebirthEvent.OnServerEvent:Connect(function(player)
local rebirths = player.leaderstats.Rebirths
local robux = player.leaderstats.Robux
local CR = 0
robux.Changed:Connect(function()
local currentRobux = 0
local robuxChanged = robux.Value - currentRobux
if rebirths.Value >=1 then
robux.Value = robux.Value + robuxChanged
currentRobux = robux.Value
print(robuxChanged)
end
end)
end)
Assume my Robux changed to 1, which fires the event. The robuxChanged variable will be 1 because 1 - 0 = 1. This satisfies the if statement and then I’m adding whatever robuxChanged variable has to robux.Value, which results in 1 + 1 = 2.
This is also because if the server is fired multiple times this would result in the callback function being connected to the robux.Changed event multiple times, you need to disconnect old connections before creating new ones.