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)
✓ ANSWER ACCEPTED
How do i teleport everyone in a server to a part?
1 answer
✓ Accepted answer
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
This discussion is preserved as it was. New answers, comments, and votes are closed.
