Character teleportation not working correctly

My character sometimes teleports right next to the pillar, but not on it?
https://gyazo.com/bb49cf1e7d6ac862457bc23bc136240f

The issue occurs occasionally, and I cannot find a way to fix it

	local HRP_OFFSET = Vector3.new(0, 1, 0)
	
	local function ChooseATeleporter(): BasePart
		if (minigame_model and minigame_model:FindFirstChild("Teleporters")) then
			return table.remove(minigame_teleporters_array, math.random(#minigame_teleporters_array)) :: BasePart
		else
			error("There are no models in workspace with that name or there is no teleporters folder")
		end
	end
	
	--Teleport the player from NotInGame to a random Teleporter
	for _, player: Player in table.clone(player_handler.PlayersNotInGame) do
		--Move players from NotInGame array into InGame array

		if not player.Character then
			continue
		end
		
		local hrp = ((player.Character):FindFirstChild("HumanoidRootPart") :: BasePart)
		
		hrp.Anchored = true
		hrp.CFrame = CFrame.new(ChooseATeleporter().Position + HRP_OFFSET,minigame_model:FindFirstChild("OriginPoint").Position)
		
		hrp.Anchored = false
	end

Even when I increase the HRP_OFFSET Y Axis, it still happens, I tried to anchor and unanchor the hrp , but the issue is still there

Thank you

I would guess that it’s an issue with the model rather than the script. You could try adding a part to where the position is set to teleport the player to and check.

for _, player: Player in table.clone(player_handler.PlayersNotInGame) do
		--Move players from NotInGame array into InGame array

		if not player.Character then
			continue
		end
		
		local hrp = ((player.Character):FindFirstChild("HumanoidRootPart") :: BasePart)
		
		hrp.Anchored = true
		local target = CFrame.new(ChooseATeleporter().Position + HRP_OFFSET,minigame_model:FindFirstChild("OriginPoint").Position)
		
		local debugPart = Instance.new("Part")
		local highlight = Instance.new("Highlight", debugPart)
		--set highlight to always on top, i forgot what the property was called
		debugPart.Size = Vector3.new(2, 2, 1)
		debugPart.Anchored = true
		debugPart.CFrame = target
		debugPart.Name = tostring(player)
		debugPart.Parent = workspace

		hrp.CFrame = target

		hrp.Anchored = false
	end

something like this and check where the script positions them

I assume that the problem has to do with you teleporting the player inside the block. You should add some more height offset to it.

1 Like

I found the issue.
I am cloning the map from ServerStorage (then Parenting to workspace) and then teleporting the characters.
However, sometimes the players get teleported to the Part before the map has time to be loaded

Gyazo

Is there a good fix to that?

Thank you

Yes, don’t move the character until the map is there.

How would I detect if the map is loaded or not? I already got StreamingEnabled, but the issue is still there

You could break your map into smaller models.

Put the problem part in the first model you clone.

This will also prevent the huge lag that occurs when a large map is loaded into a game.

You could simply add a wait. Wait a couple seconds after creating it, should be enough to fix it