The title may seem a bit complicated but allow me to explain:
I have a coin balance screen gui in game, and I also have a cannon that fires projectiles.
I am making it so when a shot is fired from this cannon into a part, and it hits the part accurately, the coin balance gui will move up by 10, so 1 shot is 10 coins and so forth.
Now, what I want to do is add a level system, so if you reach a certain amount of coins, your level goes up by 1 which unlocks new stuff.
The level system will also be a screen gui above the coin balance screen gui.
Now what I am struggling with is the level going up by 1 when a certain number is reached.
What I've done in the code below is I've TRIED to make it so that when the coin balance reaches 1000, the level goes up to 1, but for some reason it's not working.
Here is the script:
wait(1) local guiframe = game.Players.LocalPlayer.PlayerGui.softwaregui.Frame local player = game.Players.LocalPlayer local level = game.Players.LocalPlayer.PlayerGui.softwaregui.Frame.TextLabel1 local value = game.Players.LocalPlayer.PlayerGui.softwaregui.Frame.Value local level2 = game.Players.LocalPlayer.PlayerGui.softwaregui.Frame.TextLabel if value.Value >= 1000 then level.Text = value.Value if value.Value >= 1000 then level.Text = "1" end end
Help is really appreciated, as I cannot seem to solve this problem.
Excuse its simplicity if it was easy to fix, I have begun scripting just recently but that is not an excuse.
In order to add one you would do the following:
level.Text = level.Text + 1
Also, you should not be setting level.Text to the text value of the coins, that will show your level as 1000. (line 9)
Here is the revised code that I have:
wait(1) local guiframe = game.Players.LocalPlayer.PlayerGui.softwaregui.Frame local player = game.Players.LocalPlayer local level = game.Players.LocalPlayer.PlayerGui.softwaregui.Frame.TextLabel1 local value = game.Players.LocalPlayer.PlayerGui.softwaregui.Frame.Value local level2 = game.Players.LocalPlayer.PlayerGui.softwaregui.Frame.TextLabel if value.Value >= 1000 then if value.Value >= 1000 then level.Text = level.Text+1 end end
As long as the string stays all numbers this method will work. The string is converted to a number in order to do the addition, then it's converted back to a string for the text object.
Code has been fixed.
I had to merge everything together, so where all the variables were, I had to put it all into one universalcode so yeah.
I am so relieved I managed to fix it, let's just hope it doesn't break LOL
Thanks for all the help guys.