I have 2 scripts: Client and server
The problem is on my server script, where I can't add players to a table
local PlayersToTeleport = {} game.ReplicatedStorage:WaitForChild("MoveBus").OnServerEvent:Connect(function(plr, randomSeat) randomSeat.Touched:Connect(function(TouchedPart) if TouchedPart.Parent:FindFirstChild("Humanoid") then local Character = TouchedPart.Parent local Player = game.Players:GetPlayerFromCharacter(Character) local AlreadyInTable = false for _,OtherPlayer in next,PlayersToTeleport do if OtherPlayer == Player then AlreadyInTable = true end end if not AlreadyInTable then table.insert(PlayersToTeleport,Player) end end end)
Can you help me fix it?
Is this what you where attempting to accomplish?
local PlayersToTeleport = {} local seat = game.ReplicatedStorage:WaitForChild("MoveBus") local random = math.random(1,#seat) random.Touched:Connect(function(plr) if plr.Character:FindFirstChild("Humanoid") then local Character = plr.Character local Player = game.Players:GetPlayerFromCharacter(Character) local AlreadyInTable = false for _,OtherPlayer in pairs (PlayersToTeleport) do if OtherPlayer == Player then AlreadyInTable = true end end if not AlreadyInTable then table.insert(PlayersToTeleport,Player) end end end)