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;
01 | flag = game.Workspace.Flag.Flag |
02 | B = script.Parent.Blue |
03 | R = script.Parent.Red |
04 |
05 | while 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 |
14 | end |
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.) 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.
01 | flag = game.Workspace.Flag.Flag |
02 | B = script.Parent.Blue |
03 | R = script.Parent.Red |
04 |
05 | -- Your text isn't solely a number, so you need to separate the text from the number. |
06 | local function find_num(text) |
07 | for i in string.gmatch(text, "%d+" ) do |
08 | return tonumber (i) |
09 | end |
10 | end |
11 |
12 | while 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 ) |
19 | end |