Why my loadstring send me a nil calling error?

Hi devs, today I work on a load screen system and I need to use loadstring to call any operation put in a string to avoid errors. But actually I can’t call my string to see the operation result, this error occurred. → 16:14:18.591 - ServerScriptService.Script:6: attempt to call a nil value

This is my script and my LoadStringEnabled is enabled.

local clientmaster = {profile = {genre = ''}}

local task = {'clientmaster.profile.genre ~= nil'}

print(task[1])
print(loadstring(tostring(task[1]))())

Thanks for your help !

loadstring returns nil and a string which represents the error message if the source has a syntax error in it.

clientmaster.profile.genre ~= nil is an expression, and expressions are not valid statements in Lua. I don’t know what your goal here is though, or why you need loadstring for something like this.

Like I said earlier, I want to avoid to get errors. The first thing would be to verify if the profile exist, then would be to verify in the table if the gender has been selected. If a profile is not loaded then I can’t see if the gender is inside, but the script does it by default while execution and cause an error. So if I use the loadstring I could verify the expression when necessary only.

You don’t need loadstring though??

if clientmaster.profile.genre ~= nil then

end

you can’t possibly get errors with this

Not in this case.

local LoadTask = {'ClientMaster.Profile ~= nil', 'ClientMaster.Profile.gender ~= nil'} -- Here I put the tasks to execute or verify

while wait() do
	if #LoadTask > 0 then
		ClientMaster.LoadMain(true)
		for i = 1, #LoadTask do
			repeat wait()
				if loadstring(LoadTask[i])() then
					table.remove(LoadTask, i)
					break
				end
			until false
		end
		ClientMaster.LoadMain(false)
	end
end

I will try by creating a more detailed table, thanks for your time.

1 Like