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
--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)