This script is meant to make a currency textlabel that quickly increases numerically as a players currency goes up and goes down quickly (but visibly for both) as players currency goes down however if I increase my currency it goes up fine, if I decrease it after that it infinitely goes up(only visually in the textlabel since the stats increase like they should) and if I increase my currency after decreasing it it infinitely goes down.
Thanks to @Qxest for helping with formatting. Greatly appreciated! (Still don’t know if I did it to his standard but I tried.)
ChangingValue = "Waiting" local Remote = game:GetService("ReplicatedStorage").RemoteEvents:WaitForChild("Currency") --Explanatory Remote.OnServerEvent:Connect(function(player) local CashText = player.PlayerGui.ScreenGui.TextLabel -- The textlabel that displays the sum of the currency. local Amount = player.PlayerGui.Currency_Control.Currency.PreviousCurrency -- Not previous currency(will rename), was going to be previous, is the sum of currency this script uses. local Prev = player.PlayerGui.Currency_Control.CurrencyLog.Log1 --A log that updates every 0.01 seconds storing the previous sum of currency the user had player.Cash.Changed:Connect(function(NewValue) if player.Cash.Value >= Prev.Value and ChangingValue == "Waiting" then --I tried this instead of boolean just to see I am aware Boolean is more efficient but got desperate --means nothing is happening in the script right now. ChangingValue = "Adding" --When the value is increasing change the ChangingValue to "adding" in order to clarify that repeat Amount.Value = Amount.Value + 1 wait() CashText.Text = ""..Amount.Value.."" wait(.000001) --Extremely fast wait time since it's not there for efficiency, it makes sure the textlabel catches up with their real sum of money relatively quickly. --I'll be changing this probably soon so the speed it catches up by depends on the sum of money that it's increasing by. until Amount.Value == player.Cash.Value ChangingValue = "Waiting" --Same as before CashText.Text = ""..player.Cash.Value.."" --The sum of 'cash' the player has, temporary name for it. elseif player.Cash.Value <= Prev.Value and ChangingValue == "Waiting" then ChangingValue = "Subtracting" --I was tired so why the hell did I call this minusing in the previous version? repeat Amount.Value = Amount.Value - 1 wait() CashText.Text = ""..Amount.Value.."" wait(.000001) --same as before until Amount.Value == player.Cash.Value --The amount as explained before, clarifying it will stop when it hits the same sum as the cash. CashText.Text = ""..player.Cash.Value.."" --Updates to the text to whatever the cash value is just in-case there was some issue and the label isn't displaying it right. ChangingValue = "Waiting"--same as before elseif ChangingValue == "Adding" or ChangingValue == "Subtracting" then print("Do nothing") --This stops spam and was an attempt at stopping the bug I'm dscriving. Failed. end end) end)