Smok
Smok

Reputation: 3

citizen:/scripting/resource_init.lua:17: unexpected symbol near 'then'

that my code for my fiveM server and when i try to start yo thr server i get and error that say "citizen:/scripting/resource_init.lua:17: unexpected symbol near 'then'" can someone help me out?

return function(chunk)
    local addMetaData = AddMetaData

    setmetatable(_G end
    
        __index = function(t, k)
            local raw = rawget(t, k)
        end
            if raw then
                return raw
            

            return function(value)
                local newK = k
            
                if type(value) == 'table' then
                    -- remove any 's' at the end (client_scripts, ...)
                    if k:sub(-1) ==  then
                        newK = k:sub(1, -2)
                    

                    -- add metadata for each table entry
                    for _, v in ipairs(value) do
                        addMetaData(newK, v)
                    end
                else
                    addMetaData(k, value)
                end

                -- for compatibility with legacy things
                return function(v2)
                    addMetaData(newK .. '_extra', json.encode(v2))
                end
            end
        end
    })

    -- execute the chunk
    chunk()

    -- and reset the metatable
    setmetatable(_G, nil)
end

Upvotes: 0

Views: 789

Answers (1)

Nifim
Nifim

Reputation: 5021

You have many errors in your code, the error in the title is not the one the currently presents when you run this code.


First Error: :4: ')' expected near 'end'

line 4 is:

setmetatable(_G end

Should be

setmetatable(_G, {

The error is pretty unclear because this is a fairly odd mistake, i am not sure why that end was put there.


Second Error: :9: '}' expected (to close '{' at line 4) near 'if'

there is a misplaced end on line 8 that should be be on line 11. This error is expecting } because the end on line 8 completes the function definition started on line 6.


Third Error :18: unexpected symbol near 'then'

line 18 is:

if k:sub(-1) ==  then

should be something like:

if k:sub(-1) == "s" then

you need a second operand of the ==


Forth Error: :36: 'end' expected (to close 'function' at line 6) near '}'

missing end between lines 32 and 33. Pretty clear error on this one, it is worth stating the indentation ended up wonky and that can make seeing missing end's a bit more difficult

Upvotes: 1

Related Questions