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)
try and loop through the players to get all the players to the part like this
01 | -- Inside the winning part |
02 | script.Parent.Touched:Connect( function (hit) |
03 | if hit.Parent:findFirstChild( "Humanoid" ) then |
04 | local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- Getting the player that won |
05 | print (player.Name.. " has won the game" ) |
06 | for _,v in pairs (game.Players:GetPlayers()) do |
07 | -- if v.Name ~= player.Name then -- This is just for if you don't want the winning player to tp to the part |
08 | if v.Character:findFirstChild( "HumanoidRootPart" ) then |
09 | local offset = CFrame.new( 0 , 5 , 0 ) -- optional, if you don't want to be inside a part :D |
10 | v.Character.HumanoidRootPart.CFrame = script.Parent.CFrame * offset |
11 | end |
12 | end |
13 | end |
14 | end ) -- We are done |