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

How do i teleport everyone in a server to a part?

Asked by 4 years ago

Im making a obby/racing game and i want everyone to teleport to a specific part when one player touches the winning part. But i dont know how to get the names of everyone in the server, can anyone help? (sorry for bad grammar)

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

try and loop through the players to get all the players to the part like this

-- Inside the winning part
script.Parent.Touched:Connect(function(hit)
    if hit.Parent:findFirstChild("Humanoid") then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- Getting the player that won
        print(player.Name.." has won the game")
        for _,v in pairs(game.Players:GetPlayers()) do
            -- if v.Name ~= player.Name then -- This is just for if you don't want the winning player to tp to the part
            if v.Character:findFirstChild("HumanoidRootPart") then
                local offset = CFrame.new(0,5,0) -- optional, if you don't want to be inside a part :D
                v.Character.HumanoidRootPart.CFrame = script.Parent.CFrame * offset
            end
        end
    end
end) -- We are done
Ad

Answer this question