Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

:bad argument #3 to 'Text' (string expected, got nil)?

i was script in and i got a this error:bad argument #3 to 'Text' (string expected, got nil) the script is:

while true do
	local id = game.ReplicatedStorage.id:InvokeServer()
	if id[0] == 'game_tp' then
		script.Parent.Visible = true
	end
	if id[0] ~= 'game_tp' then
		script.Parent.Visible = false
	end
	wait(0.1)
	script.Parent.dec.Text = id[2]
	script.Parent.mapname.Text = id[1]
end

this is the sever script:

function id()
	return {game.ServerScriptService.game_cmds_Value, game.ServerStorage.guis.map.map_no_id.thegui.mapname.Text, game.ServerStorage.guis.map.map_no_id.thegui.dec.Text}
end
game.ReplicatedStorage.id.OnServerInvoke = id

1 comment

0

You have to check what server invoke is i think?

1 answer

✓ Accepted answer

Lua table index starts at 1 not 0 so on line 10 you are trying to assing text to a nil value as the index id[2] does not exist.

You should alos not be calling InvokeServer in a while loop with a 0.1 wait time. Send the data when it is needed to all player and update them when it changes. Constantly calling remote events / functions will overload the network reulting in lag and dropped requests.

Please review your code and how you want it to work.

Lastly you should use else with your if statment as you check if the first is equal. Better still as you are only assigning a boolean value and all comparison operators return a boolean use.

script.Parent.Visible = id[1] == 'game_tp' -- index should be 1 

Hope this helps.

2 comments

0

Table indices in all programming languages start with 0 simply because it acts as an offset for the rest of the table. This means that (0,10) would actually be 11 values because the 0 is counted.

0

Not in Lua

This discussion is preserved as it was. New answers, comments, and votes are closed.