Respawning Problem

There’s a problem where when I touch a checkpoint it’s suppose to respawn me there but instead of at the spawn which happens on and off. I’ll test the game and it’ll work and then another time it won’t. Let me know if you need more details. The issue is near character added.

Here’s the script that’s been giving me issues:

game.Players.PlayerAdded:Connect(function(player)
	local key = "player-" .. player.UserId
	
	local GetSave = DataStore:GetAsync(key) -- check for existing data 
	
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"
	
	local checkpoint = Instance.new("IntValue", leaderstats)
	checkpoint.Name = "Checkpoint"
	
	local spawnpoint = Instance.new("IntValue", leaderstats)
	spawnpoint.Name = "SpawnPoint"
	
	if GetSave then
		checkpoint.Value = GetSave
		print("Data Loaded For " .. player.Name)
	else
		checkpoint.Value = 1
		print("New Data Created For " .. player.Name)
	end
	
	player.CharacterAdded:Connect(function(character)
		repeat wait() until workspace:FindFirstChild(character.Name)

		local player = game.Players:GetPlayerFromCharacter(character)
		local respawn = cpFolder[player.leaderstats.SpawnPoint.Value]

		character.HumanoidRootPart.CFrame = respawn.CFrame + Vector3.new(0,2,0)
	end)
	
end)

try adding wait(2) after

player.CharacterAdded:Connect(function(character)

This might give a better understanding.


It’s suppose to respawn me at the SpawnPoint (not the actual one) but instead it spawns me at the beginning. It happens on and off like I said.

Do you think looping through all of the checkpoints and finding if one of them is the correct one?

For instance:

for i,v in pairs([PUT YOUR CHECKPOINT FOLDER HER]:GetChildren() 
if v.Name == respawn then
character.HumanoidRootPart.CFrame = respawn.CFrame + Vector3.new(0,2,0)
end
end

Sorry if it’s formatted badly and/or any coding inconsistencies, I was typing it off of here.

1 Like
game.Players.PlayerAdded:Connect(function(player)
	local key = "player-" .. player.UserId
	
	local GetSave = DataStore:GetAsync(key) -- check for existing data 
	
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"
	
	local checkpoint = Instance.new("IntValue", leaderstats)
	checkpoint.Name = "Checkpoint"
	
	local spawnpoint = Instance.new("IntValue", leaderstats)
	spawnpoint.Name = "SpawnPoint"
	
	if GetSave then
		checkpoint.Value = GetSave
		print("Data Loaded For " .. player.Name)
	else
		checkpoint.Value = 1
		print("New Data Created For " .. player.Name)
	end
	
	player.CharacterAdded:Connect(function(character)
		repeat wait() until workspace:FindFirstChild(character.Name)

		local player = game.Players:GetPlayerFromCharacter(character)

 for i,v in pairs(cpFolder:GetChildren()) do
		local respawn = v:FindFirstChild(player.leaderstats.SpawnPoint.Value)

		character.HumanoidRootPart.CFrame = respawn.CFrame + Vector3.new(0,2,0)
end
	end)
	
end)
1 Like