Player not spawning where they should spawn

Hi again.

I know I have been posting a lot frequently, but that is because I am a bit rusty in scripting, after taking a long break.

Now, to the point.

Below is the script that I am using to spawn the player at a certain point. Also below is a video on what happens when the player loads in.

The player does not spawn at the location.

Script
for _, descendant in pairs(spawns:GetDescendants()) do
-- Loops through the available spawns
		if descendant:IsA("NumberValue") then
			if descendant.Value == lvl.Value then
				firstSpawn = descendant.Parent
-- Assign firstSpawn to the descendants parent (aka the first checkpoint)
			end
		end
	end
	
	player.CharacterAdded:Connect(function(characterModel)
		wait(0.01)
		print("done")
		-- Make them spawn at the starting point
		characterModel.HumanoidRootPart.CFrame = CFrame.new(firstSpawn.Position + Vector3.new(0,5,0))
	end)
Video

robloxapp-20220108-1646542.wmv (841.3 KB)

I have been stuck on this for hours now, and it is annoying me. How can I solve this?

1 Like

Your code looks good to me. Does it print done in the output when your character spawns?

Here are some possible solutions that I could think of

  1. Make sure the spawn points anchored?
  2. Double check to make sure descendant.Value is actually equal to 1v1.Value.

No it doesn’t print out done.

The spawn points are all anchored.

What do you mean by “1v1.Value”?

characterModel.HumanoidRootPart.CFrame = firstspawn.CFrame
Try using this, tell me how it goes.

I want them to spawn 5 studs on top of the part. That is why it is there.

Trying to move the character right when it’s created is kind of a nightmare. It really doesn’t like to work.

Here’s what I generally do to move it:

if not character:IsDescendantOf(Workspace) then
    character.AncestryChanged:Wait()
end

task.wait()

character.HumanoidRootPart.CFrame = CFrame.new() -- Set to CFrame

I believe this has something to do with the character being client sided. If anyone has a better way of doing this please DM me.


This is not a problem. If you’d like to learn more, here is the API for the functions and operator definitions used:

CFrame.new ( Vector3 pos )
Returns a CFrame with no rotation with the position of the provided Vector3.

Vector3 Vector3 + Vector3
Returns a new Vector3 with each component of the second added to the corresponding component of the first.

I suggest waiting for a cframe change before setting it as when you spawn in your cframe is changed. Here:

	-- Loops through the available spawns
	if descendant:IsA("NumberValue") then
		if descendant.Value == lvl.Value then
			firstSpawn = descendant.Parent
			-- Assign firstSpawn to the descendants parent (aka the first checkpoint)
		end
	end
end

player.CharacterAdded:Connect(function(characterModel)
	print("done")
	-- Make them spawn at the starting point
	local rootPart = characterModel:WaitForChild("HumanoidRootPart")
	rootPart:GetPropertyChangedSignal("CFrame"):Wait()
	task.wait()
	
	characterModel.HumanoidRootPart.CFrame = CFrame.new(firstSpawn.Position + Vector3.new(0,5,0))
end)
1 Like