-
What do you want to achieve? I want my model’s clone to parented to the camera
-
What is the issue? This error keeps popping up
-
What solutions have you tried so far? I searched up youtube and devforum but no success
Keep in mind the model has multiple meshes , so i used weldConstraint. And have set up the primarypart
--Client Side
local rep = game:GetService("ReplicatedStorage")
local runs = game:GetService("RunService")
local model3D = require(rep:WaitForChild("Module3D"))
local tweeny = game:GetService("TweenService")
local uis = game:GetService("UserInputService")
local plr = game.Players.LocalPlayer
local cam = workspace.Camera
local pets = rep:WaitForChild("Pets")
local eggs = workspace:WaitForChild("Nidus")
local distance = 40
local canhatch = nil
local ishatch = false
wait(3)
local function animatebilly(billboard , openorclose)
if openorclose == true then
tweeny:Create(billboard, TweenInfo.new(0.1),{Size = UDim2.new(15, 0,20, 0)}):Play()
else
tweeny:Create(billboard, TweenInfo.new(0.2),{Size = UDim2.new(0,0,0, 0)}):Play()
wait(.3)
billboard.Enabled = false
end
wait(1)
end
for i,v in pairs(eggs:GetChildren()) do
local eggpets = pets:FindFirstChild(v.Name)
if eggpets ~= nil then
local billboardtemp = script.Template:Clone()
local container = billboardtemp:WaitForChild("Cointainer")
local frame = container:WaitForChild("Main_Frame")
local template = frame:WaitForChild("Template")
local billboardegg = script.Parent.Parent.Eggboards
local port = template:WaitForChild("Port")
billboardtemp.Adornee = v.EggMesh
billboardtemp.Name = v.Name
billboardtemp.Enabled = true
billboardtemp.Parent = billboardegg
local petz = {}
for x, pet in pairs(eggpets:GetChildren()) do
table.insert(petz, pet.Rarity.Value)
end
table.sort(petz)
for i = 1, math.floor(#petz/2) do
local j = #petz - i + 1
petz[i], petz[j] = petz[j], petz[i]
end
for _,rarity in pairs(petz) do
for _, pet in pairs(eggpets:GetChildren()) do
if pet.Rarity.Value == rarity then
local rarity = pet.Rarity.Value
local clonedtemp = template:Clone()
clonedtemp.Name = pet.Name
clonedtemp.Rarity.Text = tostring(pet.Rarity.Value).."%"
clonedtemp.Visible = true
clonedtemp.Parent = frame
local petmodel = model3D:Attach3D(clonedtemp.Port,pet:Clone())
petmodel:SetDepthMultiplier(1.2)
petmodel.Camera.FieldOfView = 5
petmodel.Visible = true
runs.RenderStepped:Connect(function()
petmodel:SetCFrame(CFrame.Angles(0,tick() % (math.pi * 2),0) * CFrame.Angles(math.rad(-10),0,0))
end)
break
else
continue
end
end
end
runs.RenderStepped:Connect(function()
if plr:DistanceFromCharacter(v.EggMesh.PrimaryPart.Position) < distance then
if billboardtemp.Name ~= v.Name then
canhatch = true
animatebilly(billboardtemp, true)
billboardtemp.Enabled = true
else
canhatch = true
animatebilly(billboardtemp, true)
billboardtemp.Enabled = true
end
else
animatebilly(billboardtemp, false)
canhatch = false
end
end)
end
end
local function hatch1(pet,egg)
print(pet)
local eggmesh = egg:FindFirstChild("EggMesh"):Clone()
for i,v in pairs(eggmesh:GetChildren()) do
if v:isA("BasePart") then
v.Anchored = true
v.CanCollide = false
runs.RenderStepped:Connect(function()
local cf = CFrame.new(0, 0,-eggmesh.PrimaryPart.Size.Z * 2)
eggmesh:SetPrimaryPartCFrame(cam.CFrame * cf)
end)
eggmesh.Parent = cam
end
end
end
uis.InputBegan:Connect(function(input)
local billboardtemp = script.Template
local clonedtemp = billboardtemp.Cointainer.button
if input.KeyCode == Enum.KeyCode.E then
if canhatch == true and plr.Character ~= nil and ishatch == false then
local plrps = plr.Character.HumanoidRootPart.Position
local nearsetg
for i,v in pairs(eggs:GetChildren()) do
if nearsetg == nil then
nearsetg = v
else
--where the error pops up
if (plrps - v.PrimaryPart.Position).Magnitude < (nearsetg.PrimaryPart.Position - plrps).Magnitude then
nearsetg = v
end
end
end
local result = rep:WaitForChild("EggHatchingRemotes") :WaitForChild("hatchserver"):InvokeServer(nearsetg)
if result ~= nil then
ishatch = true
hatch1(result,nearsetg)
wait(3)
ishatch = false
end
end
end
end)
--Server Side
wait(2)
local plrs = game:GetService("Players")
local function addplrs(player)
for i,v in pairs(game.ServerStorage.EggHatchingData:GetChildren()) do
v:Clone().Parent = player
end
end
plrs.PlayerAdded:Connect(addplrs)
for i, player in pairs(plrs:GetPlayers()) do
addplrs(player)
end
game.ReplicatedStorage.EggHatchingRemotes.hatchserver.OnServerInvoke = function(player,egg)
local eggmodel = workspace.Nidus:FindFirstChild(egg.Name)
if eggmodel ~= nil then
local price = eggmodel.Price
local currency = eggmodel.Currency.Value
if player.leaderstats[currency].Value >= price.Value then
local chosenpet = game.ReplicatedStorage.Pets[eggmodel.Name]:GetChildren()[math.random(1, #game.ReplicatedStorage.Pets[eggmodel.Name]:GetChildren())]
return chosenpet
else
return false
end
end
end