Obby instant respawn and stage system

I don’t know why sometimes i will get teleported to the default spawn.

here is a module

local CheckPointsFolder = game.Workspace:WaitForChild("PlayerCheckPoints")
local SpawnPoint = CheckPointsFolder:WaitForChild("SpawnPoint")
local Players = game:GetService("Players")

local function ToStage(Player)
	
	local PlayerStage = Player:WaitForChild("leaderstats").Stage
	local PlayerCharacter = Player.Character
	if PlayerStage.Value > 0 then
		wait()
		PlayerCharacter:MoveTo(CheckPointsFolder:WaitForChild(PlayerStage.Value).Position + Vector3.new(0,5,0))
	else
		wait()
		PlayerCharacter:MoveTo(SpawnPoint.Position + Vector3.new(0,5,0))
	end
	print("Teleported "..Player.Name.." to stage")
end

return ToStage
	

here is the instant respawn script

local Players = game:GetService("Players")

local function OnPlayerAdded(Player)
	Player.CharacterAdded:Connect(function(Character)
		repeat wait()
			
		until Character.Humanoid
		Character.Humanoid.Died:Connect(function()
			Player:LoadCharacter()
		end)
	end)
end

Players.PlayerAdded:Connect(OnPlayerAdded)

here is the script that teleport player when player died

local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
local ToStage = require(ServerScriptService:WaitForChild("ServerHandler"):WaitForChild("ToStage"))

local Connections = {}

local function OnDied(Player)
	Player.leaderstats.Death.Value = Player.leaderstats.Death.Value + 1
	Connections[Player.Name]:Disconnect()
	local PlayerCharacter = Player.CharacterAdded:Wait()
	local Humanoid = PlayerCharacter:WaitForChild("Humanoid")
	if Humanoid then
		ToStage(Player)
		Connections[Player.Name] = PlayerCharacter.Humanoid.Died:Connect(function()
			OnDied(Player)
		end)
		print("Teleported "..Player.Name.." to stage")
	end

end

local function OnPlayerAdded(Player)
	
	local PlayerCharacter = Player.Character or Player.CharacterAdded:Wait()
	Connections[Player.Name] = PlayerCharacter.Humanoid.Died:Connect(function()
		OnDied(Player)
	end)
	
end

local function OnPlayerRemoving(Player)
	if Connections[Player.Name] then
		Connections[Player.Name] = nil
	end
end

Players.PlayerAdded:Connect(OnPlayerAdded)
Players.PlayerRemoving:Connect(OnPlayerRemoving)
1 Like

You don’t need to do this. All you need to do is set Players.RespawnTime to 0.
You could also set Player.SpawnLocation to the obby spawn location.

2 Likes

as @megukoo said, you can set the respawn time to 0, if you still want to do player:LoadCharacter() then you can do player:LoadCharacter(game.Workspace.SpawnLocation)

2 Likes

im not using roblox SpawnLocation , im using a part as a spawn

1 Like