How can I implement this into this script?

How can I make it so players spawn in and all the excess plates with a blank ‘Owner’ value are deleted? I’m not the most familiar with for i, v in pairs stuff, so if anyone can help me out here it will be appreciated!

basically I need players teleporting to a random plate upon round start and excess plot deleting implemented in this script

local rep = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")

local events = 5
chosenEvent = ""
local ce = chosenEvent
local plateTemplate = game.ServerStorage.Player_Baseplates

local values = rep.Values
local current = values.CurrentEvent
local eventtype = current.EventType
local highlight = current.ObjectToHighlight
local status = values.Status

local inRound = false
local inGame = workspace.Ingame
local reqPlayers = 2

local function chooseEvent()
	chosenEvent = math.random(1, events)
	ce = chosenEvent
end

local function executeEvent()
	if ce == 1 then
		eventtype.Value = "Player"
		current.Value = "A player will get +10 jump power"
		status.Value = current.Value
	elseif ce == 2 then
		eventtype.Value = "Player"
		current.Value = "A player will become sparkly"
		status.Value = current.Value
	elseif ce == 3 then
		eventtype.Value = "Arena"
		current.Value = "Arena: Fire will fall from the sky"
		status.Value = current.Value
	elseif ce == 4 then
		eventtype.Value = "Plate"
		current.Value = "Someone's plate will light on fire"
		status.Value = current.Value
	elseif ce == 5 then
		eventtype.Value = "Plate"
		current.Value = "Someone's plate will flip upside-down"
		status.Value = current.Value
	end
end

while task.wait() do
	if #players:GetChildren() >= reqPlayers then
		wait(1)
		for i = 1,15 do
			status.Value = "Intermission: "..15-i
			task.wait(1)
		end
		status.Value = "Teleporting players..."
		--Here
	else
		status.Value = "Waiting for minimum of 2 players."
	end
end
2 Likes

Make a table of plates and use a for i, v in pairs to loop through a model or folder where all of the plates are held.

how it works

local plates = {} - a table of the plates
for index, variable in pairs(platesFolder:GetChildren()) do -- each child of the plates folder will be considered a variable, while the index will be the platesFolder itself.
      table.insert(plates, variable))
end

then after you can assign each player to a random plate like so.

for i, v in pairs(game.Players:GetPlayers()) do
      player.Character.PrimaryPart.CFrame = plates[math.random(1, #plates)].CFrame
end
1 Like

I didn’t understand that very well.
Could you give more details of what you mean? Or even resume it?

1 Like

I have 64 plates, do I have to put them all in a table?

1 Like

Are these plates all located in a folder? If so like I said, you need to do a loop on the folder and then you can add each plate to the table.

Personally, I would create the plates for each player individually, instead of creating 64 at once and then deleting them after. It depends on how you set up your plates though, a picture of your explorer would help.

I’m not very sure about the owner value thing, but the op said that they wanted to teleport players to random plates.

Can you add excess plate deletion?

Could you show your explorer? Is plateTemplate one plate or all of them?

plateTemplate is a new set of plates to replace the ones destroyed by the events that occur

Is there any parts in workspace.Player_Baseplates?

Player_Baseplates is the current set of plates thats there by default on server startup, same as plateTemplate

Instead of making a separate folder just clone the original and then let that one get destroyed.

can we focus on the original point of the topic

now how do i make excess plates destroyed

Were trying to get more information because the post is a bit lackluster and the things you describe are a bit hard to understand.

Your script doesn’t even teleport the players yet, that’s why we need more info before we help you.

I drafted some code for you, but it may not work due to the few details I had to work with:

--//Services
local ServerStorage = game:GetService("ServerStorage")
local rep = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")

--//Variables
local plateTemplate = ServerStorage.Player_Baseplates
local values = rep.Values
local current = values.CurrentEvent
local eventtype = current.EventType
local highlight = current.ObjectToHighlight
local status = values.Status
local currentPlates = workspace.Player_Baseplates
local inGame = workspace.Ingame

--//Controls
local RNG = Random.new()
local events = 5
local chosenEvent = ""
local ce = chosenEvent
local inRound = false
local reqPlayers = 2

--//Tables
local plateOwners = {}

--//Functions
local function chooseEvent()
	chosenEvent = math.random(1, events)
	ce = chosenEvent
end

local function executeEvent()
	if ce == 1 then
		eventtype.Value = "Player"
		current.Value = "A player will get +10 jump power"
	elseif ce == 2 then
		eventtype.Value = "Player"
		current.Value = "A player will become sparkly"
	elseif ce == 3 then
		eventtype.Value = "Arena"
		current.Value = "Arena: Fire will fall from the sky"
	elseif ce == 4 then
		eventtype.Value = "Plate"
		current.Value = "Someone's plate will light on fire"
	elseif ce == 5 then
		eventtype.Value = "Plate"
		current.Value = "Someone's plate will flip upside-down"
	end
	
	status.Value = current.Value
end

while true do
	if #players:GetPlayers() >= reqPlayers then
		task.wait(1)
		
		for i = 1, 15 do
			status.Value = "Intermission: ".. 15 - i
			task.wait(1)
		end
		
		if #players:GetPlayers() < reqPlayers then
			continue
		end
		
		status.Value = "Teleporting players..."
		
		--//Create all plates
		currentPlates:ClearAllChildren()
		plateTemplate:Clone().Parent = currentPlates
		
		--//Clear plateOwners table
		table.clear(plateOwners)
		
		--//Teleport players to unowned plates
		for i, player in ipairs(players:GetPlayers()) do
			local randomPlate = currentPlates:GetChildren()[RNG:NextInteger(1, #currentPlates:GetChildren())]
			
			while plateOwners[randomPlate] do
				randomPlate = currentPlates:GetChildren()[RNG:NextInteger(1, #currentPlates:GetChildren())]
			end
			
			plateOwners[randomPlate] = player
			player:MoveTo(randomPlate.Position)
		end
		
		--//Destroy unowned plates
		for i, plate in ipairs(currentPlates) do
			if not plateOwners[plate] then
				plate:Destroy()
			end
		end
	else
		status.Value = "Waiting for minimum of 2 players."
		players.PlayerAdded:Wait()
	end
end

yeah sorry i didnt give enough info

 Position is not a valid member of Folder "Workspace.Player_Baseplates.Player_Baseplates" - Main:82
  Stack Begin
  Script 'ServerScriptService.Main', Line 82 - Main:82
  Stack End

I believe I have fixed it, but also, is there a value in each plate called “Owner”? And if so, what type of value is it?

Code:

--//Services
local ServerStorage = game:GetService("ServerStorage")
local rep = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")

--//Variables
local plateTemplate = ServerStorage.Player_Baseplates
local values = rep.Values
local current = values.CurrentEvent
local eventtype = current.EventType
local highlight = current.ObjectToHighlight
local status = values.Status
local currentPlates = workspace.Player_Baseplates
local inGame = workspace.Ingame

--//Controls
local RNG = Random.new()
local events = 5
local chosenEvent = ""
local ce = chosenEvent
local inRound = false
local reqPlayers = 2

--//Tables
local plateOwners = {}

--//Functions
local function chooseEvent()
	chosenEvent = RNG:NextInteger(1, events)
	ce = chosenEvent
end

local function executeEvent()
	if ce == 1 then
		eventtype.Value = "Player"
		current.Value = "A player will get +10 jump power"
	elseif ce == 2 then
		eventtype.Value = "Player"
		current.Value = "A player will become sparkly"
	elseif ce == 3 then
		eventtype.Value = "Arena"
		current.Value = "Arena: Fire will fall from the sky"
	elseif ce == 4 then
		eventtype.Value = "Plate"
		current.Value = "Someone's plate will light on fire"
	elseif ce == 5 then
		eventtype.Value = "Plate"
		current.Value = "Someone's plate will flip upside-down"
	end
	
	status.Value = current.Value
end

while true do
	if #players:GetPlayers() >= reqPlayers then
		task.wait(1)
		
		for i = 1, 15 do
			status.Value = "Intermission: ".. 15 - i
			task.wait(1)
		end
		
		if #players:GetPlayers() < reqPlayers then
			continue
		end
		
		status.Value = "Teleporting players..."
		
		--//Clear plateOwners table
		table.clear(plateOwners)
		
		--//Create all plates
		currentPlates:ClearAllChildren()
		
		for plate in ipairs(plateTemplate:GetChildren()) do
			plate:Clone().Parent = currentPlates
		end
		
		--//Teleport players to unowned plates
		for i, player in ipairs(players:GetPlayers()) do
			local randomPlate = currentPlates:GetChildren()[RNG:NextInteger(1, #currentPlates:GetChildren())]
			
			while plateOwners[randomPlate] do
				randomPlate = currentPlates:GetChildren()[RNG:NextInteger(1, #currentPlates:GetChildren())]
			end
			
			plateOwners[randomPlate] = player
			player:MoveTo(randomPlate.Position)
		end
		
		--//Destroy unowned plates
		for i, plate in ipairs(currentPlates) do
			if not plateOwners[plate] then
				plate:Destroy()
			end
		end
		
		--//Main game
	else
		status.Value = "Waiting for minimum of 2 players."
		players.PlayerAdded:Wait()
	end
end

Owner is in every plate, and it’s a stringvalue that determines who is the owner of a plate

ServerScriptService.Main:76: attempt to index number with 'Clone' - Main:76
 Stack Begin
 Script 'ServerScriptService.Main', Line 76 - Main:76
 Stack End