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

Why is "Argument 1 missing or nil" on Line 19?

Here, I have a script which is supposed to generate obstacles after two players are in the game and the "Game starting!" phase has passed.

t = 0

while true do
	local placeHolder = game.Workspace.PlaceHolders:GetChildren()
	local rooms = game.ReplicatedStorage:WaitForChild("GeneratedObs"):GetChildren()
	local s = script.Stat
	local plrs = game.Players:GetChildren()
	if #plrs > 1 then
		t = 15
		repeat
			t = t-1
			s.Value = "Intermission... "..t
			wait(1)	
		until t == 0
		s.Value = "Game starting!"
		wait(5)
		local chosenRoom = rooms[math.random(1,#rooms)]:Clone()
		chosenRoom.PrimaryPart = chosenRoom.Floor
		chosenRoom:SetPrimaryPartCFrame(placeHolder.CFrame)
		placeHolder:Destroy()
		chosenRoom.Parent = game.Workspace
		-- each room is located in a folder called "GeneratedObs" under ReplicatedStorage.
	else
		s.Value = "Two or more players are needed to play."
		wait(1)
	end
end

In Solo mode, the script works fine where there is only one player in the game, therefore the second condition is met and the part of the script where the error is is never executed. However, when I start a local server with 2 players, 5 seconds after the "Game starting!" phase an error appears in the server output, saying that "Argument 1 is missing or nil" on Line 19. I have tried moving the script into StarterPlayerScripts after doing some research, however this has not fixed the issue and I'm curious as to why the error is appearing. Any help is much appreciated!

1 answer

✓ Accepted answer

The placeHolder refers to GetChildren(), which will return a table, not a model. Hence, there is no CFrame of a table. Are you trying to choose a random room from the placeHolders? If so, just run a for loop using placeHolder.

local num = math.random(1,max) --set max to the amount of maps you have
local randomMap

 for i,v in ipairs(placeHolder) do
   if num == i then
    randomMap = v
  end
end

Then you can do SetPrimaryPartCFrame(randomMap)

2 comments

0

Yes, that's what I am trying to do! :)

0

I've edited my answer, insert the code into the function

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