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
local player = game.Players.LocalPlayer
tele = {"Tp1","Tp2","Tp3","Tp4","Tp5","Tp6","Tp7","Tp8","Tp9","Tp10","Tp11","Tp12","Tp13"}
spawnz = game.Workspace.Spawnz:GetAllChildren()
randomIndex = math.random(1,#tele)
randomElement = tele[randomIndex]
randomColor = BrickColor.new(randomElement)

function SpawnPlayer()
local torso = player:WaitForChild("Character")
local torso = player.Character:WaitForChild("Torso")
local spawnedIndex = math.random(1, #spawnz)
randomElement = spawnedIndex()
torso.CFrame = CFrame.new(spawn.Position + Vector3.new(0,3,0))
end


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.

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:

local Spawnz = Workspace.Spawnz:GetChildren() --Not GetAllChildren

Game.Players.PlayerAdded:connect(function(player)
    local lastSpawn = nil
    player.CharacterAdded:connect(function(character)
        repeat
            local spawn = Spawnz[(math.random(1, #Spawnz)]
        until spawn ~= lastSpawn
        lastSpawn = spawn

        wait() --Let the Character fully load

        character.Torso.CFrame = spawn.CFrame + Vector3.new(0, 3, 0)
    end)
end)

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

Answer this question