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

Spawn Them Not on top of each other or Spawn to SpawnLocation?

Asked by 9 years ago

So this script teleport all players to the certain position that I put. But then when all players teleport, they all teleport on top of each other and glitch to the top of the roof which I don't like. So how do I make this:

target = Vector3.new(-52.8, 10.5, 9.4) -- The positon I want them to teleport.
for i, v in pairs(game.Players:GetChildren()) do 
v.Character.Torso.CFrame = CFrame.new(target + Vector3.new(0, i * 5, 0))
end

Spawn to SpawnLocation or not spawn on top of each other?

0
So you want it like a minigame thing where they teleport into a certain area? Or I thought you were talking about spawns. Please explain better please! EzraNehemiah_TF2 3552 — 9y
0
So for example I said "respawn" then all of us will respawn to spawnlocation CjGamer1454 0 — 9y

2 answers

Log in to vote
1
Answered by 9 years ago
local target = CFrame.new(-52.8, 10.5, 9.4)

for _,plr in next, game.Players:GetPlayers() do --Always use next, ... It's easier in my opinion. Also always always always use game.Players:GetPlayers(). It's more efficient.
    plr.Character.Torso.CFrame = target
end

Should help you out.

0
I wouldn't make a claim that `:GetPlayers()` is more efficient; it's basically the same thing... Programmix 285 — 9y
1
Ha.. no. :GetPlayers() will /always/ return all of the player objects, where :GetChildren() will return anything that is in Players... so if you put a part in Players it would return that and you don't wanna count that as a player, do you? 0xDEADC0DE 310 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

Use the PlayerAdded and CharacterAdded event. The Character Added event will call when a player and the player's character has spawned.


PlayerAdded

It's like a Touched event. It is an event for the Players service. So we can do this:

game:GetService("Players").PlayersAdded:connect(function(player) --see the "player"? This is the player
    print(player.Name) --Prints the player's name.
end)

CharacterAdded

This will check if a player's character has spawned. The easiest way to get the player is through player added.

game:GetService("Players").PlayersAdded:connect(function(player)
    player.CharacterAdded:connect(function(character) --the "character" is the character.
        character.Humanoid.Health = 0 --This is like a loop kill...
    end)
end)


Finished Product

local target = CFrame.new(-52.8, 10.5, 9.4)

game:GetService("Players").PlayersAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        character.Torso.CFrame = target
    end)
end)



Hope this helps! This is for a spawn script. If you want something else please msg me. I can make any script for you.

0
How bout they spawn in the spawnlocation? CjGamer1454 0 — 9y

Answer this question