Bad argument #2 (interval is empty), Should work?

Hello, I’m back again with a scripting problem.

local Players = game:GetService("Players")
local Assign = game.Workspace:WaitForChild("AssignPersonalities")
local Personalitiess = game.Workspace:WaitForChild("Personalities")

if Personalitiess then
local Personalities = game.Workspace.Personalities:GetChildren()
local AppliedDummies = game.Workspace.AppliedDummies:GetChildren()
	if Assign then
		
			if #Players:GetPlayers() == 2 then
			local random_P1 = Personalities[math.random(1,#Personalities)]
			local random_D1 = AppliedDummies[math.random(1,#AppliedDummies)]
			random_P1.Parent = random_D1
			random_D1.Parent = game.Workspace.ChosenDummies
			random_P1.Humanoid:MoveTo(random_D1.HumanoidRoot.Position + Vector3.new(0,0,-2))
		end

This script gives the error “Bad argument #2 (interval is empty)” at line 11 (I’m guessing 12 too.)

game.Workspace.Personalities:GetChildren() should be greater than 1 since it’s the amount of players and there must be 2 players for this to run. (“Personalities” too).

I’m new to scripting so, sorry if it’s a silly mistake.

Disclaimer: “AppliedDummies” and “Personalities” are folders in case that makes a difference.

The folder “Personalities” in Workspace is empty. You must have a logic error elsewhere - maybe you’re confusing a folder name?

1 Like

Floor the index value for random_P1 and D1.

local random_P1 = Personalities[math.floor(math.random(1,#Personalities))]
local random_D1 = AppliedDummies[math.floor(math.random(1,#AppliedDummies))]

There might be other problems that I didn’t catch.

1 Like

Tested! It doesn’t seem to be empty.
Screenshot_444

Thanks for your concern but I already fixed it myself (and with a bit of help). Will post it as a reply in case you are curious.

So what was happening was “game.Workspace:WaitForChild(“AssignPersonalities”)” was happening before the folder “Personalities” or “AppliedDummies” had any children. This was because of another script. thanks to @PupNetx for making me notice this, sorry guys. :grimacing: