Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 5 years ago
Edited 5 years ago

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.

0
What does the output say? danglt 185 — 5y
0
The output says nothing. LordBlueSky 10 — 5y
0
In line 5 you already got the Value of value, so why are you doing value.Value Synth_o 136 — 5y
0
Because the value is inside of Frame, can you help? LordBlueSky 10 — 5y
View all comments (4 more)
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. DinozCreates 1070 — 5y
0
value.Changed:Connect(function() DinozCreates 1070 — 5y
0
I've fixed it. LordBlueSky 10 — 5y
0
did you do the thing i said? also put (solved) in title please DinozCreates 1070 — 5y

2 answers

Log in to vote
0
Answered by
Vmena 87
5 years ago
Edited 5 years ago

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.

0
I hate to be the bearer of bad news but that code did not work. LordBlueSky 10 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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.

Answer this question