I'm trying to teleport players that are inside of a table to another location within the game, i need there to be at least 4 players in the table for the count down to start. I'm not trying to teleport the group of players to another game i'm trying to teleport the group of players to a different spot in the game.
--This is how you would teleport a player using CFrame, in the simplest way local Teleportto = --the path to the part you want to teleport to local from = script.Parent -- this is just fo example local function TeleportToPosition(part) local hum = part.Parent:FindFirstChild("HumanoidRootPart") --HumanoidRootPart is the thing we want to teleport if hum then hum.CFrame = Teleportto.CFrame + Vector3.new(0,5,0) end end -- I am going to use a Touched event for this from.Touched:Connect(TeleportToPosition) --That would be how you teleport players
I think if you are trying to wait for certain players and teleport you can use this.
First, I think you can wait until the table is storing more than 4 value.
local table = {} local teleportLocation = CFrame.new(--Copy the position CFrame by placing the brick to your desired position and type in commandbar this : print(workspace.Part.CFrame)) local function checkPlayers() if #table >=4 then return true else return false end end --This code Will Check If number of Players Stored In Table if over or equal to 4.
Then, make a event that inserts new player into table.
--The event Fires(Like the part was touched. If you want to make Gui that registers player, you will also have to use remote events to tell server script that the player is willing to enter a teleport.) part.Touched:Connect(function(plr) if plr:FindFirstChild("Humanoid") then--Checks if the thing that touched the part is actually a player. table.insert(table, 1, plr) end end
Now, you would want to make a script that fires as soon as the player ready to teleport is over 4.
while wait(5) do -- I just like to make the script wait 5 seconds so it`s less laggy then checking every milliseconds if checkPlayers then --do Count Down Maybe? Its up To you. for _, value in pairs (table) do --You should learn how for loops work to understand better if you don't already, but I will tell you anyways. This basically goes through every value in table. _ and v can be changed to any names, since it`s a variable. local teleportMainPart = v:FindFirstChild("Head") teleportMainPart.CFrame = teleportLocation end end end
I think this codes should work if I didn`t mistake. Hope It helps :D