01 | local player = game.Players.LocalPlayer |
02 | tele = { "Tp1" , "Tp2" , "Tp3" , "Tp4" , "Tp5" , "Tp6" , "Tp7" , "Tp8" , "Tp9" , "Tp10" , "Tp11" , "Tp12" , "Tp13" } |
03 | spawnz = game.Workspace.Spawnz:GetAllChildren() |
04 | randomIndex = math.random( 1 ,#tele) |
05 | randomElement = tele [ randomIndex ] |
06 | randomColor = BrickColor.new(randomElement) |
07 |
08 | function SpawnPlayer() |
09 | local torso = player:WaitForChild( "Character" ) |
10 | local torso = player.Character:WaitForChild( "Torso" ) |
11 | local spawnedIndex = math.random( 1 , #spawnz) |
12 | randomElement = spawnedIndex() |
13 | torso.CFrame = CFrame.new(spawn.Position + Vector 3. new( 0 , 3 , 0 )) |
14 | end |
15 |
16 |
17 | player.Character.Humanoid.Died:connect(SpawnPlayer) |
I don't know where this script should be plus what kind of script is it like local or none local script. I want the players to spawn in different spawn each time they die.
It should be in the workspace is this a free model or something you created if its a free model you need a model in the workspace named Spawnz with something actually in the model
This script is a LocalScript, but this code is very broken. A spawn-handling script should be a normal Script, and be in the ServerScriptService:
01 | local Spawnz = Workspace.Spawnz:GetChildren() --Not GetAllChildren |
02 |
03 | Game.Players.PlayerAdded:connect( function (player) |
04 | local lastSpawn = nil |
05 | player.CharacterAdded:connect( function (character) |
06 | repeat |
07 | local spawn = Spawnz [ (math.random( 1 , #Spawnz) ] |
08 | until spawn ~ = lastSpawn |
09 | lastSpawn = spawn |
10 |
11 | wait() --Let the Character fully load |
12 |
13 | character.Torso.CFrame = spawn.CFrame + Vector 3. new( 0 , 3 , 0 ) |
14 | end ) |
15 | end ) |
This should accomplish what I think you're trying to do.