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

How to equally distribute plates?

Asked by 4 years ago

So I'm trying to make a "Plates of Fate" type game and I got stuck on the part where I have to give each player their own plate and teleport them to their plate. This is what I managed to get so far but it only clones one plate and doesn't teleport the players.

local plates = serverstorage:WaitForChild("Plates")
local plateholder = game.Workspace:WaitForChild("Plates")
local players = game:GetService("Workspace").Players.Value

function addplate(player)
    local allplates = plates:GetChildren()
    local newplate = allplates[math.random(1, #allplates)]:clone()
    newplate.Parent = workspace.Plates
    newplate.Player.Value = player.Name
end

while true do
    print ("start")


    --Wait for players
    while true do
        wait(5)
        contestants = {}
        for _, player in pairs(game.Players:GetPlayers()) do
            if player and player.Character then
                local humanoid = player.Character:WaitForChild("Humanoid")
                if humanoid and humanoid.Health > 0 then
                    table.insert(contestants, player)
                end
            end
        end
        if #contestants >= 2 then
            break
        else
            statustag.Value = "Waiting for Players"
            timertag.Value = -1
        end
    end


    --Load Plates
    statustag.Value = "Loading Plates"
    timertag.Value = -1
    plateholder:ClearAllChildren()
    wait(2)
    for _, player in pairs(contestants) do
        addplate(player)
    statustag.Value = "Plates Loaded!"
    wait(3) 

    --Teleport players to plate
    local roundplates = plateholder:GetChildren()
    for _, player in pairs(contestants) do
        if player and player.Character and #roundplates > 0 then
            local torso = player.Character:WaitForChild("Torso")
            local humanoid = player.Character:WaitForChild("Humanoid")
            local spawn = plateholder:FindFirstAncestor(player)
            if spawn and torso and humanoid then
                humanoid.Health = 100
                humanoid.WalkSpeed = 16
                torso.CFrame = CFrame.new(spawn.Position + Vector3.new(0, 3, 0))

                local matchtag = Instance.new("StringValue")
                matchtag.Name = "MatchTag"
                matchtag.Parent = player.Character

                    end
                end
            end
        end

Answer this question