Error using AlignPosition and AlignOrientation in my simulator game (also I think SetNetworkOwner)

Hello again to all roblox developers. While I was programming my game and solving some errors I came across another very important error for which I cannot find a solution. You see, when a player enters my game and that player has pets saved, the first time he enters the pets are positioned correctly surrounding the player. But the second time it enters the same server, the alignPosition and alignOrientation are not detected and the pet is not positioned, the only thing it does is position itself at the spawnpoint. In order not to add so much information in my other topics, you can see videos of how the pets look positioned. I tried to use a SetNetworkOwner on each of the pet parts and add alignOrientation and position on each of the pet parts, but it still doesn’t work. Also check that the folders that the player has when exiting are deleted to avoid errors. But even doing all that, it still doesn’t work. It seems that the error comes from alignPosition and orientation not being found, or that’s what I think. I leave you the script if anyone has any ideas. The first is localScript to position the pets, and the second is to add SetNetworkOwner to each of the pet parts the player has. Thank you very much and greetings :slight_smile:

--Here is the localScript code
local RS = game:GetService("RunService")
local players = game:GetService("Players")
local Player = game.Players.LocalPlayer

local character = Player.Character or Player.CharacterAdded:Wait()
local playerPets = game.Workspace:FindFirstChild("PlayerPets")

local circle = math.pi *2
local minimunRadius = 4


local function PositionPets(character, folder)
	local foldertable = folder:GetChildren()
	for i, pet in pairs(foldertable) do
		local radius = minimunRadius + #foldertable
		local angle = i * (circle/ #foldertable)	
		local x = math.cos(angle) * radius
		local z = math.sin(angle) * radius

		local walkSineWave = math.max(math.sin((tick() + pet.TimeDelay.Value)* 10) / 2,-0.1)
		local walkFrontBackCos = math.cos((tick()+pet.TimeDelay.Value )* 10)/7
		local hoverSineWave =	math.sin((tick()+ pet.TimeDelay.Value) * 5) / 10
		local hoverSineWaveIdle = math.sin((tick() + pet.TimeDelay.Value)) / 10

		local petCFrame = character.HumanoidRootPart.CFrame * CFrame.new(x, 5, z)
		if character.Humanoid.MoveDirection.Magnitude > 0 then
			if pet.Flying == false then
				petCFrame *= CFrame.new(0, walkSineWave, 0) * CFrame.Angles(walkFrontBackCos,0,0)
			else
				petCFrame *= CFrame.new(0,hoverSineWave,0)
			end
		else
			if pet.Flying.Value == true then
				petCFrame *= CFrame.new(0,0.2 + hoverSineWaveIdle, 0)
			end
		end

		--pet.PrimaryPart.AlignOrientation.CFrame = petCFrame.Rotation
		for i, part in pet:GetChildren() do
			if part:IsA("BasePart") then
				part.AlignPosition.Position = petCFrame.Position
				part.AlignOrientation.CFrame = petCFrame.Rotation
			end
			pet.PrimaryPart.AlignPosition.Position = petCFrame.Position
			pet.PrimaryPart.AlignOrientation.CFrame = petCFrame.Rotation
		end
		
		
	end
end

RS.RenderStepped:Connect(function()
	if not character then 
		character = Player.Character 
		return 
	end 
	for _, petFolder in playerPets:GetChildren() do
		if petFolder.Name == Player.Name then
			--print("You are the correct player")
			PositionPets(character, petFolder)
		end
	end
end)
--Here's the script code
local playerPets = game.Workspace.PlayerPets
local RS = game:GetService("RunService")

game.Players.PlayerAdded:Connect(function(player)
	
	RS.PostSimulation:Connect(function()
		for i, playerFolder in playerPets:GetChildren() do
			if playerFolder.Name == player.Name then
				for i, pet in playerFolder:GetChildren() do
					for i, part in pet:GetChildren() do
						if part:IsA("BasePart") then
							part:SetNetworkOwner(player)
						end
					end
				end
			end
		end
	end)
	
end)
2 Likes

huh my bad lol, i don’t know why script doesn’t change position to new character.
change that

if not character then 
		character = Player.Character 
		return 
	end 

to this

character = Player.Character or Player.CharacterAdded:Wait()
1 Like

Hello again! I’m glad to see you again, I tried the changes you told me but it still doesn’t work, I’m leaving a video of what the final result looks like in case it helps a little more to find solutions

i couldn’t reproduce this bug, because i don’t have second account to launch. are u sure that u published changes?

Yes, I checked 3 times that the changes have been published and they are done correctly, now I am doing the game again to see if I can find the error, although it will take me two days to finish it but hey, I hope to find the solution, while I leave this post in case there is any idea on how to solve it

You could create and delete folder when player joined and leaving
with their saved pets using datastore

I think I already have it done, in playerPets the folder is deleted when the player leaves and enters the game, causing the pets to be also deleted, and the folder where the pets are saved through serialization is also deleted because She is related to the player, and when he leaves, she does not have a parent to stay with. I think the error is in SetNetworkOwner but I don’t know why that error occurs. Since the code there seems correct to me and the alignPosition and alignOrientation work correctly, the only thing that does not work is updating the position of the pets