I'm using roblox studio client test using 2-4 players and when they all join at the same time only one base spawns and not the rest. I know people use :WaitForChild("") or something like that. Can someone help me? Heres my code
local table = game.ReplicatedStorage:WaitForChild("Teams"):GetChildren()
local random = math.random(1,#table)
local base = table[random]
game.Players.PlayerAdded:Connect(function(player)
while true do
wait()
if base.Owner.Value == "" then
base.Name = player.name.."'s Base"
base.Owner.Value = player.name
base.Parent = game:WaitForChild("Workspace")
local spawnbase = Instance.new("SpawnLocation",base)
spawnbase.Position = base.SpawnPoint.Position
spawnbase.Duration = 3
spawnbase.Anchored = true
spawnbase.Transparency = 1
spawnbase.CanCollide = false
break
end
end
end)
game.Players.PlayerRemoving:Connect(function(player)
base.Owner.Value = ""
base:Destroy()
end)

1 comment
Your script is currently setup where only one base is selected, per line 3. Though I would never recommend using a while loop in this fashion, try moving line 3 after line 5. That would break line 24, which you could fix with some rescripting. Make an effort and I'll help