How do I teleport my player once he dies?

So I need to teleport my player to its original stage once it dies, here is my killscript, how would I add in the code so it would go to its appropriate stage?

This is what I have got now, and I don’t know how to continue as it won’t work.

local KillPart = script.Parent
local humanoid
local Players = game.Players
local TelPart1 = game.Workspace.TelParts.SimThemed
local TelPart2 = game.Workspace.TelParts.OldThemed

KillPart.Touched:Connect(function(hit)
	if hit.Parent:IsA("Model") and hit.Parent:FindFirstChild("Humanoid") then
		hit.Parent.Humanoid.Health = 0
		KillPart.CanCollide = false
		task.wait(1)
		KillPart.CanCollide = true
		local player = Players:GetPlayerFromCharacter(hit.Parent)
		local StageValue = player.leaderstats.Stage.Value
		if hit.Parent.Humanoid.Health == 100 then
			if StageValue == 0 then
				hit.Parent:PivotTo(TelPart1.TelPart1.CFrame)
			end
		end

	end
end)

you can use CharacterAdded event to detect player respawn.

also guessing you’re gonna make a folder for checkpoints, they way i’d do it is make the checkpoints’ name numbers and loop through the folder, if the tonumber(v) matches the player’s stage value you’d pivot the character to that checkpoint

EDIT: just read the entire post instead of just writing instantly and i’ve realised you wanna tp the character to the first stage.

Thanks for the reply! Although I am confused with how I would need to write the for loop, could you help me out?

sorry for being late i was asleep, what for loop are you talking about?

This is what I mean. I have tried using characteradded but in general it won’t work

for example

player.CharacterAdded:Connect(function(character)
	for i, v in pairs(game.Workspace.Checkpoints:GetChildren()) do
		if tonumber(v.Name) == player.leaderstats.Stage.Value then
			character:PivotTo(v.CFrame)
		end
	end
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.