Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.