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:
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.
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)
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.
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,
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.
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.