How to make a player appear in a certain position after player resets character?

So I create my own spawn locations and after player joins the game character spawn in a certain position.
So the main question is: how do I make the player spawn in a certain position after he reset his character?

this is the current code:

game.Players.ChildAdded:Connect(function(player)
	repeat wait() until player.Character ~= nil
	local spawnLocations = game.Workspace.spawn_locations:GetChildren()
	local selectedSpawnLocation = spawnLocations[math.random(1, #spawnLocations)]
	player.Character.HumanoidRootPart.CFrame = selectedSpawnLocation.CFrame
end)
game:GetService("Players").PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local spawnLocations = workspace.spawn_locations:GetChildren()
		local selectedSpawnLocation = spawnLocations[math.random(#spawnLocations)]
		character:PivotTo(selectedSpawnLocation.CFrame)
	end)
end)

When entering the game and after resetting, the character spawns not at the selected points
This script isnt working

(upd: also I tried it before)

What do you mean not at the selected points? Does it spawn at a spawn location or at 0,0,0?

Try uploading the game and test in a live server. I don’t know what’s happening but your character might not load.

the problem i think is that :PivotTo() tp’s the player higher up because it thinks theres no space there

PivotTo() does what SetPrimaryPartCFrame() does, but with a higher precision. MoveTo() does what you said.

i know, but it was just an idea

Same thing happening in live game. My character loads properly.

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		repeat wait() until character ~= nil
		local spawnLocations = game.Workspace.spawn_locations:GetChildren()
		local selectedSpawnLocation = spawnLocations[math.random(1, #spawnLocations)]
		character:PivotTo(selectedSpawnLocation.CFrame)
	end)
end)

this worked

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