Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Bugs when multiple people join at the same time?

Asked by 4 years ago

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)

0
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 Shawnyg 4330 — 4y

Answer this question