Player teleporting outside spawnbox [Solved?]

My problem is when i try to move the character (mostly with cframe) the first one that joined (for some reason) spawns outside the box, i have only tried with two players, i dont know if it happens with more players.

I have tried disabling player collision, “LobbySpawn” has Cancollide, touch and query disabled, i have tried using other functions (Set primary part cframe, pivot to and much more)or straight out just changing Position or cframe, this always hapened:

This is how the box looks like:

game.Players.PlayerAdded:Connect(function(plr)
	local function spawnpos(chr)
		local PhysicsService = game:GetService("PhysicsService")
		for _, bodyPart in pairs(chr:GetChildren()) do
			if bodyPart:IsA("BasePart") then
				PhysicsService:SetPartCollisionGroup(bodyPart, "HELLOLETMEINTOYOURHOUSE")
			end
		end
		if game.ServerStorage.State.Value == "LOBBY" then
			chr:PivotTo(game.Workspace["LobbySpawn"].CFrame)
		elseif game.ServerStorage.State.Value == "ROUND" then
			local random = "Spawn".. math.random(1, #game.Workspace:WaitForChild("Spawns"):GetChildren())
			chr:PivotTo(game.Workspace:FindFirstChild("Spawns"):FindFirstChild(random).CFrame)
		end
	end
	plr.CharacterAdded:Connect(spawnpos)
end)

I have tried finding an error similar to this, i have found none.

1 Like

The use of :PivotTo may not be ideal under these circumstances, especially if your experiencing issues with player positioning. Instead, you can directly set the primary parts cframe to the lobby spawn cframe:

game.Players.PlayerAdded:Connect(function(plr)
	local function spawnpos(chr)
		local PhysicsService = game:GetService("PhysicsService")
		for _, bodyPart in pairs(chr:GetChildren()) do
			if bodyPart:IsA("BasePart") then
				PhysicsService:SetPartCollisionGroup(bodyPart, "HELLOLETMEINTOYOURHOUSE")
			end
		end
		if game.ServerStorage.State.Value == "LOBBY" then
			chr:SetPrimaryPartCFrame(game.Workspace["LobbySpawn"].CFrame)
		elseif game.ServerStorage.State.Value == "ROUND" then
			local randomSpawn = game.Workspace:WaitForChild("Spawns"):GetChildren()[math.random(1, #game.Workspace:WaitForChild("Spawns"):GetChildren())]
			chr:SetPrimaryPartCFrame(randomSpawn.CFrame)
		end
	end
	plr.CharacterAdded:Connect(spawnpos)
end)
1 Like

Try using :WaitForChild(), perhaps the spawn box hasn’t loaded yet when the first player joined.

1 Like

You don’t have to :WaitForChild on server anything because server got loaded everything instantly

1 Like

Have you tried directly positioning the HumanoidRootPart to the spawn location because you are trying to pivot the character (assuming

is the character in question) itself rather than the root part that connects to the character, which has a main positioning property. Try using a Vector3 or a CFrame method. This is my first time on the forum posting so my resources are limited, forgive me if I am wrong.

1 Like

i used :SetPrimaryPartCFrame originally, i put it again and it still does it, i put the roof in the same collison groups as the players as a temporary fix,

1 Like

yeah, i have tried directly modyifying the .CFrame and .Position property, for some reason it still teleported me outside the box

1 Like

“LobbySpawn” is always in the workspace

1 Like

Are there any more lines before game.Players.PlayerAdded:Connect(function(plr)? If so they may be yielding the script and cause the first player to be ignored.

2 Likes

Don’t position the HumanoidRootPart. That doesn’t work correctly.

Since the player’s character is a model, have you tried using Model:PivotTo()? It takes a CFrame so you would use it like this:

local position = Vector3.new(x, y, z)
char:PivotTo(CFrame.new(position))

That always works. If it doesn’t, then you need to check your coordinates of where you’re sending the player to.

EDIT

I just looked at your code and you are using PivotTo(). The problem might be in your compound statement. Try doing one thing at a time on each line and print stuff. It seems to me that something is not getting the correct position.

Nope, thats the full code, idk why its happening

Never ever us epivot to,use MoveTo()

It was some other script that was doing it, idk tho?