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

I am trying to disable a spawn and let player spawn in different spawn, but it only works in studio?

Asked by 6 years ago

So when you first spawn in, you spawn in the first specified spawn, then when you die it will disable that spawn and enable the other spawn, it works fine in studio but it bugs out in game on Roblox. Here is script:

workspace.Model.SpawnLocation.Enabled = true
workspace.Cell.SpawnLocation.Enabled = false
wait(1) --lets player load in
workspace.Model.SpawnLocation.Enabled = false
workspace.Cell.SpawnLocation.Enabled = true

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

You might want to use some of roblox's built in "events".

So for example you would use CharacterAdded to see when the player spawns in. Then you can teleport them to your desired spot.

Here is some code I made for this effect.

local LAG_TIME = .01

local playerFirstSpawn = {}

local firstSpawn = workspace:WaitForChild("Tele1")
local secondSpawn = workspace:WaitForChild("Tele2")

function characterAdded(character)
    local isPlayerFound = false
    wait(LAG_TIME)
    for i,v in pairs(playerFirstSpawn) do

        if playerFirstSpawn[i] == character.Name then
            table.remove(playerFirstSpawn, i)

            character.HumanoidRootPart.CFrame = firstSpawn.CFrame
            isPlayerFound = true
        end
    end
    if not isPlayerFound then
        character.HumanoidRootPart.CFrame = secondSpawn.CFrame
    end
end


game.Players.PlayerAdded:connect(function(player)
    table.insert(playerFirstSpawn, player.Name)
    print(playerFirstSpawn[1])
    print(#playerFirstSpawn)

    player.CharacterAdded:connect(characterAdded)
end)
Ad

Answer this question