Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Level GUI not increasing when a certain coin balance is reached? [SOLVED]

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.

8 comments

0

What does the output say?

0

The output says nothing.

0

In line 5 you already got the Value of value, so why are you doing value.Value

0

Because the value is inside of Frame, can you help?

0

i believe the issue is that you're only checking to see if the value is over 1000 one time. you'd need to check every time its changed.

0

value.Changed:Connect(function()

0

I've fixed it.

0

did you do the thing i said? also put (solved) in title please

2 answers

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.

1 comment

0

I hate to be the bearer of bad news but that code did not work.

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.