[SOLVED][help]stringsplit not working right

for some reason i have tried to convert a script from cfx server to fx using the stringsplit

function stringsplit(inputstr, sep)
    if sep == nil then
        sep = "%s"
    end
    local t={} ; i=1
    for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
        t[i] = str
        i = i + 1
    end
    return t
end

and it just makes an error

Error running system event handling function for resource MGCRPInventory: citizen:/scripting/lua/scheduler.lua:39: Failed to execute thread: server.lua:36: attempt to call a nil value (global 'splitString')
stack traceback:
        server.lua:36: in upvalue 'handler'
        citizen:/scripting/lua/scheduler.lua:124: in function <citizen:/scripting/lua/scheduler.lua:123>
stack traceback:
        [C]: in function 'error'
        citizen:/scripting/lua/scheduler.lua:39: in field 'CreateThreadNow'
        citizen:/scripting/lua/scheduler.lua:123: in function <citizen:/scripting/lua/scheduler.lua:92>

any help would be appreciated!

Is not the same as

So, the fix is simple… Rename your function to “splitString”

1 Like

so in the stringsplit rename the function:

function stringsplit(inputstr, sep)
    if sep == nil then
        sep = "%s"
    end
    local t={} ; i=1
    for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
        t[i] = str
        i = i + 1
    end
    return t
end

to

function splitString(inputstr, sep)
    if sep == nil then
        sep = "%s"
    end
    local t={} ; i=1
    for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
        t[i] = str
        i = i + 1
    end
    return t
end

Edited this is correct if you get the same error i do!

would i have to clear cache after that? oh and btw thanks for the quick response!

You shouldn’t have to. Just use the restart <resource> command and it should work.

thanks for your quick responses and this solves the solution.