I need help with my script problem

  1. What do you want to achieve? Keep it simple and clear!
    My script doesn’t work after a round

  2. What is the issue? Include screenshots / videos if possible!
    I believe that this part of the script doesn’t work:

for i, v in pairs(game.Players:GetChildren()) do
	local Position = game.ServerStorage.PlatePositions:GetChildren()[math.random(1, #game.ServerStorage.PlatePositions:GetChildren())]
	Position.Parent = game.ServerStorage.UsedPositions

	local Plate = game.ServerStorage.Plate:Clone()
	Plate.Name = v.Name
	Plate.Parent = workspace.Plates
	Plate.Position = Position.Position
	v.Character.HumanoidRootPart.CFrame = Plate.CFrame + Vector3.new(0, 5, 0)
	v.TeamColor = game.Teams.Playing.TeamColor
end

here’s the full script:

local Timer = 20
local IsIntermission = true
local Players = game:GetService("Players")
local WaitingForMorePlayers = false

-- Functions

function Intermission()
	repeat

		local PlayerAmount = #Players:GetPlayers()

		if PlayerAmount >= 2 then
			repeat
				Timer -= 1
				game.ReplicatedStorage.Announce:FireAllClients("Intermission: " .. Timer)
				task.wait(1)
			until Timer == 0 or WaitingForMorePlayers == true 
		else
			if 2 - PlayerAmount == 1 then
				game.ReplicatedStorage.Announce:FireAllClients("Waiting for " .. 2 - PlayerAmount .. " player...")
				WaitingForMorePlayers = true
			else
				game.ReplicatedStorage.Announce:FireAllClients("Waiting for " .. 2 - PlayerAmount .. " players...")
				WaitingForMorePlayers = true
			end
		end

		if Timer == 0 then
			IsIntermission = false
		end

		task.wait()

	until IsIntermission == false
end

function PlayRandomEvent()
	local Event = script.Events:GetChildren()[math.random(1, #script.Events:GetChildren())]
	local PickedPlate = workspace.Plates:GetChildren()[math.random(1, #workspace.Plates:GetChildren())]
	game.ReplicatedStorage.Announce:FireAllClients(Event.EventAnnouncement.Value)

	task.wait(5)

	game.ReplicatedStorage.Announce:FireAllClients(" ")
	local Clone = Event:Clone()
	Clone:ClearAllChildren()
	Clone.Parent = PickedPlate
	Clone.Disabled = false

	task.wait(1.5)
end	

function EndGame()

	IsIntermission = true

	for i, v in pairs(game.Players:GetChildren()) do
		if v.TeamColor == game.Teams.Playing.TeamColor then
			v:WaitForChild("leaderstats"):WaitForChild("Wins").Value += 1
			v.TeamColor = game.Teams.Lobby.TeamColor
			v.Character.Humanoid.Health = 0
			game.ReplicatedStorage.Announce:FireAllClients(v.Name .. " wins!")
		end
	end

	workspace.Plates:ClearAllChildren()

	for i, v in pairs(game.ServerStorage.UsedPos:GetChildren()) do
		v.Parent = game.ServerStorage.PlatePositions
	end

	wait(5)

	Timer = 5
	Intermission()

end

-- Game

while wait() do
	Intermission()

	for i, v in pairs(game.Players:GetChildren()) do
		local Position = game.ServerStorage.PlatePositions:GetChildren()[math.random(1, #game.ServerStorage.PlatePositions:GetChildren())]
		Position.Parent = game.ServerStorage.UsedPositions

		local Plate = game.ServerStorage.Plate:Clone()
		Plate.Name = v.Name
		Plate.Parent = workspace.Plates
		Plate.Position = Position.Position
		v.Character.HumanoidRootPart.CFrame = Plate.CFrame + Vector3.new(0, 5, 0)
		v.TeamColor = game.Teams.Playing.TeamColor
	end

	wait()

	repeat
		PlayRandomEvent()

		AlivePlayers = 0
		for i, v in pairs(game.Players:GetChildren()) do
			if v.TeamColor == game.Teams.Playing.TeamColor then
				AlivePlayers += 1
			end
		end

		if AlivePlayers <= 1 then
			EndGame()
		end

		task.wait()

	until IsIntermission == true
end
  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried to do everything and nothing worked, it seems im missing something

What exactly is not working? Please give an error, a video, or something. We will help with your code, we will not guess what your code does

here is the error:

ServerScriptService.GameHandler:40: invalid argument #2 to ‘random’ (interval is empty)

my plate generation isn’t working after it’s used once

Couldn’t you put everything under a ‘while true do’ loop and put the intermission and game round together? this will make it repeat forever

example:

while true do

-- game round

-- check if everyones dead

-- intermission

end

-- it will loop again

Ignore @incognitobot_rblx that won’t solve your issue. He just seems to want to clutter pages.

Your error is pretty basic and a simple google search would have had results,

Whatever this is (inside of the math.random()) is nil.

but it’s already under a while wait() do loop

That is really rude of you to say so. I am only trying to help. Would you like me to flag you?

Yes, I’ve just realised, sorry

the reason why its nil is that a part of my script is not working after its used once

I think the reason why you’re getting an error is because the # in front of game is referencing game as # game instead of #"game.ServerStorage.PlatePositions:GetChildren())

you could do soemthing like

local PlatePositions = game.ServerStorage.PlatePositions:GetChildren()

#PlatePositions -- use this to reference the number of children in PlatePositions

That is false information sorry, but we will need more context, send the line that is erroring. Obviously, something doesn’t exist.

local PickedPlate = workspace.Plates:GetChildren()[math.random(1, #workspace.Plates:GetChildren())]

you need to put game in front of workspace because unless workspace is a variable, it will not work

workspace.Plates:GetChildren()

That doesn’t exist in your workspace, either create it or, if it does exist then it just hasn’t loaded yet and try using “FindFirstChild()”

Once again false information, the interpreter reads them the exact same.

You do not need to be rude. I’m only trying to help (although I’m not that good at scripting as you can tell, unlike some people)

I am not trying to be rude, I am just correcting your information so you can learn. If I wanted to be rude I would be continuing to aggress.

btw, what I’m writing isn’t exactly false information because it still is correct, maybe just not what you would do

also im putting “i think” in front of everything because i am not 100% sure

This is my last time responding to you, sense you seem to want to continue aggressing. It IS false information, both ways work, however you are saying that only one way does.

In my opinion, if you aren’t confident enough in your solution then you shouldn’t be posting it.

I did not know the other way works, you can simply correct me by saying “both ways actually work”, no need to flag it as false information

I’m pretty sure that when you tried to get the number of children in the “Plates” folder, there wasn’t plate inside because they hadn’t loaded yet, just like what @noahrepublic said.

Maybe try adding workspace.Plates.ChildAdded:Wait() before you assign “PickedPlate”. This will make the script wait until any plate gets inside the folder and prevent it from erroring.

Preview:

local Event = script.Events:GetChildren()[math.random(1, #script.Events:GetChildren())]
workspace.Plate.ChildAdded:Wait()
local PickedPlate = workspace.Plates:GetChildren()[math.random(1, #workspace.Plates:GetChildren())]
game.ReplicatedStorage.Announce:FireAllClients(Event.EventAnnouncement.Value)
1 Like