Egg System HumanoidRootPart not getting detected

Hello fellow Scripters!

Ive been having an issue with my recent egg system, currently when im in the hatch distance the animation wont play and the script wont work. Any idea on how to fix it?

Script:

local TweenService = game:GetService("TweenService")
local RS = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local UIS = game:GetService("UserInputService")

local LocalPlayer = Players.LocalPlayer
local PlayerGui = LocalPlayer:WaitForChild("PlayerGui")

local EggsFolder = workspace:WaitForChild("EggsFolder")
local EggBillboard = RS:WaitForChild("GUIS"):WaitForChild("EggBillboard")
local SharedModules = RS:WaitForChild("Shared")

local EggBillboards = PlayerGui:WaitForChild("EggBillboards")

local EggModule = require(SharedModules:WaitForChild("Eggs"))

local HatchDistance = 8

task.wait(5)

for _, eggModel in EggsFolder:GetChildren() do
	local NewEggBillboard = EggBillboard:Clone()
	NewEggBillboard.Name = eggModel.Name
	NewEggBillboard.Size = UDim2.fromScale(0, 0)
	NewEggBillboard.Adornee = eggModel.BillboardGuiLocation
	NewEggBillboard.Enabled = false
	NewEggBillboard.Parent = EggBillboards
	
	local EggData = nil
	
	for i, v in EggModule.Eggs do
		if tostring(i) == eggModel.Name then
			EggData = v
			break
		end
	end
	
	if EggData == nil then return end
	
	for i, v in EggData.Pets do
		local Template = NewEggBillboard.MainFrame.Container.Template:Clone()
		Template.Name = v.PetName
		Template.PetName.Text = v.PetName
		Template.Visible = true
		Template.Parent = NewEggBillboard.MainFrame.Container
	end
end

local function AnimateBillboard(BillboardGui, OpenOrClose)
	if OpenOrClose then
		BillboardGui.Enabled = true
		TweenService:Create(BillboardGui, TweenInfo.new(0.1, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {Size = BillboardGui:GetAttribute("OriginalSize")}):Play()
	else
		TweenService:Create(BillboardGui, TweenInfo.new(0.1, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {Size = UDim2.fromScale(0, 0)}):Play()
		task.wait(0.2)
		BillboardGui.Enabled = false
	end
end

RunService.Heartbeat:Connect(function()
	for _, eggModel in EggsFolder:GetChildren() do
		local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
		if Character == nil then continue end
		if (Character.HumanoidRootPart.Position - eggModel.PrimaryPart.Position).Magnitude <= HatchDistance then
			if EggBillboards[eggModel.Name].Size ~= EggBillboards[eggModel.Name]:GetAttribute("OriginalSize") then
				AnimateBillboard(EggBillboards[eggModel.Name], true)
			end
		else
			if EggBillboards[eggModel.Name].Size ~= UDim2.fromScale(0, 0) then
				AnimateBillboard(EggBillboards[eggModel.Name], false)
			end
		end
	end
end)

Any help is aprreciated!

1 Like

Do you have any errors if you are

  • can you send a screenshot of the error
  • what part of the script is getting the error

It shows no errors in the output.

It also sometimes never has the Basic Egg billboard which makes no sense


I fixed the issue!
Idk what the problem was but i recoded it, Thanks for your help 5uphi