:PivotTo() getting overwritten by spawn location

When the script first runs the player and the spawn points pivots are the same but shortly after the players pivot resets to the default spawn point

local function SpawnPlayer(player)
	local spawnPoint = spawnPoints[math.random(1, #spawnPoints)]
	local character = player.Character
	
	for _, part in pairs(character:GetDescendants()) do -- fade in
		if part:IsA("BasePart") and part.Name ~= "HumanoidRootPart" and part.Name ~= "CollisionPart" then
			part.Transparency = 1
			TweenService:Create(part, TweenInfo.new(.5), {Transparency = 0}):Play()
		end
	end
	
	character:PivotTo(spawnPoint:GetPivot() + Vector3.new(0, 0, 5))
	print(spawnPoint:GetPivot())
	print(character:GetPivot())
	print("spawned in")
	
	task.wait(2)
	print(character:GetPivot())
end
  17:38:44.684  -31.087265, 6, -26.4034042, 1, 0, 0, 0, 1, 0, 0, 0, 1  -  Server - StartupHandler:30
  17:38:44.684  -31.087265, 6, -21.4034042, 1.00000191, -2.98023757e-08, 1.19209389e-07, -2.98023757e-08, 1.00000191, -2.98023508e-08, 1.19209389e-07, -2.98023508e-08, 1  -  Server - StartupHandler:31
  17:38:44.684  spawned in  -  Server - StartupHandler:32
  17:38:46.690  -98.9897919, -144.357666, 57.0750885, 1, 0, 0, 0, 1, 0, 0, 0, 1  -  Server - StartupHandler:35
2 Likes

you are probably trying to teleport player before his character even constructed, call character:WaitForChild("HumanoidRootPart") to wait until he is ready

2 Likes

This isn’t a solution, but what you have here is kind of an anti-pattern, you shouldn’t have both a spawn location and behavior that spawns the player in arbitrary positions.

1 Like

Just make your spawn points regular Parts, not SpawnLocation instances, or set SpawnLocation.Enabled to false. The spawning code is running after you set the pivot, when the character gets parented to Workspace.

Did you mean to have Vector3.new(0,5,0) here to spawn the avatar above a spawn pad? Your code will try to position the avatar with their root part at the height of the spawn point part, but horizontally offset from it 5 studs in the world Z direction.

2 Likes

@EmilyBendsSpace They aren’t spawn locations they are regular parts just called that, and yes i intended to spawn the player above the spawn point (since when was z not vertical?)

@xnlogical I don’t know if you think the parts are spawn locations or that i have another spawn location but what i mean by the default spawn location is just 0, 0, 0 (but if i have another actual spawn location it does go to that)

@HafuPlay Unfortunately this doesn’t work I also tried just doing print(time()) before and after and there’s no difference so that’s not the issue

Does the original spawning in logic run at the same time as your SpawnPlayer(player) function? From what I understood, you have two methods to spawn the player in at the same time and one is overriding the other. Could you show the code that spawns the player to the default spawn point?

There is no code to spawn them to the default spawn point, if you have no spawn points roblox just defaults to 0, 0, 0 which is what is happening

Is the code in StarterCharacterScripts?

No, but putting it there doesn’t fix the issue if thats what your suggesting

Hey! I checked ya script and your PivotTo() is actually working correctly your points prove it as well that means something is overriding your position AFTER your function runs not before It’s most likely a SpawnLocation is teleporting the character after spawn or another script is moving the character ( pretty common in loaders and character handlers )

What you can do to fix this is :

  1. Disable the spawn locations overriding your position
for _, spawn in pairs(workspace:GetDescendants()) do
	if spawn:IsA("SpawnLocation") then
		spawn.Enabled = false
	end
end
  1. Force the position AFTER everything finishes
local function SpawnPlayer(player)
	local spawnPoint = spawnPoints[math.random(1, #spawnPoints)]
	local character = player.Character
	local hrp = character:WaitForChild("HumanoidRootPart")

	for _, part in pairs(character:GetDescendants()) do
		if part:IsA("BasePart") and part.Name ~= "HumanoidRootPart" and part.Name ~= "CollisionPart" then
			part.Transparency = 1
			TweenService:Create(part, TweenInfo.new(.5), {Transparency = 0}):Play()
		end
	end

	task.wait()
	task.wait()

	character:PivotTo(spawnPoint:GetPivot() + Vector3.new(0, 0, 5))
end

Try it and let me know if it fixes your issue.

1 Like

+Y has always been Up in Roblox :grin: