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

Can Anyone Help me With this Spawn script or local script?

Asked by 10 years ago
01local player = game.Players.LocalPlayer
02tele = {"Tp1","Tp2","Tp3","Tp4","Tp5","Tp6","Tp7","Tp8","Tp9","Tp10","Tp11","Tp12","Tp13"}
03spawnz = game.Workspace.Spawnz:GetAllChildren()
04randomIndex = math.random(1,#tele)
05randomElement = tele[randomIndex]
06randomColor = BrickColor.new(randomElement)
07 
08function SpawnPlayer()
09local torso = player:WaitForChild("Character")
10local torso = player.Character:WaitForChild("Torso")
11local spawnedIndex = math.random(1, #spawnz)
12randomElement = spawnedIndex()
13torso.CFrame = CFrame.new(spawn.Position + Vector3.new(0,3,0))
14end
15 
16 
17player.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.

2 answers

Log in to vote
1
Answered by 10 years ago

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

Ad
Log in to vote
0
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
10 years ago

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:

01local Spawnz = Workspace.Spawnz:GetChildren() --Not GetAllChildren
02 
03Game.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 + Vector3.new(0, 3, 0)
14    end)
15end)

This should accomplish what I think you're trying to do.

Answer this question