I want to teleport all players in a table when the NumPlayers value is 1. But I'm not sure how to get all the players in the table and teleport them to the game. Here's my code:
local PlayerAmount = 1 -- How many players have to be in a teleporter for it to teleport
local TeleportService = game:GetService("TeleportService")
local PlayerNum = script.Parent.Players -- How many players are in the teleporter
local debounce = false
PlayersToTP = {}
script.Parent.SurfaceGui.TextLabel.Text = "Players: 0/10"
PlayerNum.Changed:Connect(function()
script.Parent.SurfaceGui.TextLabel.Text = "Players: "..PlayerNum.Value.."/10"
end)
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and debounce == false then
debounce = true
local Humanoid = hit.Parent.HumanoidRootPart
local char = hit.Parent
local player = game.Players:GetPlayerFromCharacter(char)
Humanoid.CFrame = CFrame.new(game.Workspace.TeleportPart.Position + Vector3.new(0,3,0))
PlayerNum.Value = PlayerNum.Value +1
table.insert(PlayersToTP,player)
wait(1.5)
debounce = false
if PlayerNum.Value <= PlayerAmount then
TeleportService:Teleport(4820164617, PlayersToTP)
end
elseif debounce == true then
print("Debounce is true")
end
end)
The error comes on line 28. I'm not sure how to fix this, if somebody could help me that would be great! Thanks!

1 comment
Thanks for the answer, greatly explained and easy to read. Works great!