Workspace.Part.Script:10: invalid argument #2 (string expected, got nil)

Hey! I’m making a script which will clone the first person who touches a part in roblox studio.

My script:

local table1 = {}

function addPlayerToTable(player)
	local name = player.Parent.Name
	table.insert(table1, name)

	print(table1[1])
	
	local function nicetest()
		local clone = game.Players[table1[0]].Character
		clone.Archivable = true
		local clone2 = clone:clone()
		clone2.Parent = game.Workspace
		clone.Archivable = false

		local cloned2 = game.ServerStorage.script:Clone()
		cloned2.Parent = clone2.Humanoid
		cloned2.Enabled = true

	end
	nicetest()
end


script.Parent.Touched:Connect(addPlayerToTable)

The error I’m getting: Workspace.Part.Script:10: invalid argument #2 (string expected, got nil)

This is a ServerScript and it’s in a part inside workspace.

All help appreciated :slight_smile:

1 Like

Lua tables start with 1 so you should change it to

local clone = game.Players[table1[1]].Character

It was that easy, thanks! Also how to reduce lag when it clones the player. The game lags so much I cannot even move after it cloned.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.