Why does my character not get spawned in the right place?

My character for some reason isn’t spawning in the right location. Im not sure why though

	player.CharacterAdded:Connect(function(character)
		local checkpoint = workspace.Checkpoints:FindFirstChild(stage.Value, true)
		print(checkpoint.Name)
		if checkpoint ~= nil then
			character.HumanoidRootPart.CFrame = checkpoint.CFrame
			print("Done")
		end
	end)

Kinda stupid question, but, you’re calling an undefined value at line 1(which is player)
Have you defined it before the script chunk?

sorry didn’t show the full thing

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"

	local stage = Instance.new("IntValue", leaderstats)
	stage.Name = "Stage"
	stage.Value = 0

	player.CharacterAdded:Connect(function(character)
		local checkpoint = workspace.Checkpoints:FindFirstChild(stage.Value, true)
		print(checkpoint.Name)
		if checkpoint ~= nil then
			character:SetPrimaryPartCFrame(checkpoint.CFrame)
			print("Done")
		end
	end)
end)

I changed it a bit but it still didn’t work in that chunk

Just asking before posting, do you want it to be like this:

  1. Player touches spawnlocation
  2. The player will always spawn at the touched spawn

or

  1. Player joins the game
  2. A spawn gets reserved
  3. No one rather than that exact player can spawn on that spawn

i want it so any player can spawn on that spawn when they spawn in the game

If i understood correctly, you meant:

  1. Player joins the game
  2. Player spawns on that one spawn
  3. Another player joins the game
  4. Another player spawn on that one spawn again
1 Like

yes you are correct

If you actually mean it, insert a SpawnLocation wherever you want.


Also, delete the following code chunk in your script so it wont run any errors:

	player.CharacterAdded:Connect(function(character)
		local checkpoint = workspace.Checkpoints:FindFirstChild(stage.Value, true)
		print(checkpoint.Name)
		if checkpoint ~= nil then
			character:SetPrimaryPartCFrame(checkpoint.CFrame)
			print("Done")
		end
	end)