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

Attempted to concatenate a nil value? [SOLVED]

Asked by 10 years ago

I'm making a ROBLOX implementation of CSS (to be used with GUIs) with a ModuleScript, and I'm getting an error. (These scripts are long but you shouldn't need to read the whole thing)

ModuleScript:

01local module = {}
02 
03local function splitStylesheet(sheet)
04    local split = {}
05 
06    local char = 1
07    local line = 1
08    for i = 1, string.len(sheet) do
09        if string.sub(sheet, char, char) ~= "}" then
10            table.insert(split, line, split[line]..string.sub(sheet, char, char))
11            char = char + 1
12        else
13            line = line + 1
14            char = char + 1
15        end
View all 78 lines...

Script I'm using the Module with (it's in a ScreenGui):

1local css = require(game.Workspace.CSS)
2 
3css.readStylesheet("stylesheet1", "constructor1{background:none;}constructor2{background:none;}")

Output:

120:53:53.339 - Workspace.CSS:10: attempt to concatenate field '?' (a nil value)
220:53:53.359 - Stack Begin
320:53:53.359 - Script 'Workspace.CSS', Line 10 - upvalue splitStylesheet
420:53:53.360 - Script 'Workspace.CSS', Line 73 - field readStylesheet
520:53:53.360 - Script 'Players.Player.PlayerGui.PlayerGui.Main', Line 3
620:53:53.361 - Stack End

Anyone know what the problem is? Thanks to anyone who helps :)

0
string[line] is nil while you're still inserting the value into the table, so you're going to have to find a way around using string[line]. I would also suggest using tostring() to make sure the entire value you're going to insert is a string. Spongocardo 1991 — 10y
0
Not sure what you mean by this... DevJackB 55 — 10y
1
On line 10 when you attempt to call split[line], there is no value in spilt at the spot corresponding with the value for line. You then attempt to concatenate that value (nil) with something else, which is why the error is being thrown. BlackJPI 2658 — 10y
0
Couldn't have put it any better myself @Masta Spongocardo 1991 — 10y

Answer this question