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

Why doesn't this GUI script work?

Asked by 10 years ago

I have two problems; A) Roblox Studio crashes when I try to test the game (It works if I remove the script that is at the bottom) and B) When a player captures the flag in the middle of my game, I want the GUI to start adding points for what ever team captured it, which is does not currently.

Heres the code;

01flag = game.Workspace.Flag.Flag
02B = script.Parent.Blue
03R = script.Parent.Red
04 
05while true do
06    if flag.BrickColor == "Bright blue" then
07        wait(1)
08        B.Text = "Blue:"..1+B.Text
09    if flag.BrickColor == "Bright red" then
10        wait(1)
11        R.Text = "Red:"..1+B.Text
12    end
13    end    
14end

B is the GUI responsible for the amount of points blue team has and R is for the amount of points for the red team.

Please help!

1 answer

Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
10 years ago

1.) You need a wait in the while loop, because if both aren't true those waits won't do anything.

2.) You can't add numbers and strings, just like you can't add a+1. However, if the string is a number you can convert it so you can add it. - tonumber(b.Text) + 1

3.) You need an elseif, because the second if isn't going to be checked if the first one isn't true.

01flag = game.Workspace.Flag.Flag
02B = script.Parent.Blue
03R = script.Parent.Red
04 
05-- Your text isn't solely a number, so you need to separate the text from the number.
06local function find_num(text)
07    for i in string.gmatch(text, "%d+") do
08        return tonumber(i)
09    end
10end
11 
12while true do
13    if flag.BrickColor == "Bright blue" then
14        B.Text = "Blue:"..find_num(B.Text) + 1
15    elseif flag.BrickColor == "Bright red" then
16        R.Text = "Red:"..find_num(B.Text)  + 1
17    end    
18    wait(1)
19end
Ad

Answer this question