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!

2 comments
Yes, that's what I am trying to do! :)
I've edited my answer, insert the code into the function