This requires some background context:
I have a ScrollingFrame in the PlayerGUI which has a script called SetupBuy, which creates the list of items in the ScrollingFrame based on a template so that no matter how many items I add, it’ll automatically update the ScrollingFrame list.
This is the script:
local buyableSeeds = game:GetService("ReplicatedStorage"):WaitForChild("buyableSeeds"):GetChildren()
for i, v in pairs(buyableSeeds) do
local template = script:WaitForChild("SeedSelectionTemplate"):Clone()
template.Parent = script.Parent
template.Name = v.Name
template.Visible = true
local templateSeedDetails = template.SeedDetails
templateSeedDetails.SeedName.Text = v.Name
template.Price.Value = v:GetAttribute("PriceCents")
templateSeedDetails.SeedPrice.Text = template.Price.Value.."¢"
local templateSeedPayment = template.SeedPayment
if v:GetAttribute("PriceCents") == 0 then
templateSeedPayment.BuyButton_Cents.Text = "Free"
else
templateSeedPayment.BuyButton_Cents.Text = v:GetAttribute("PriceCents").."¢"
end
if v:GetAttribute("PriceRobux") == 0 then
templateSeedPayment.BuyButton_Robux.Text = "Free"
else
templateSeedPayment.BuyButton_Robux.Text = v:GetAttribute("PriceRobux")..utf8.char(0xE002)
end
local seedClone = v:Clone()
seedClone.Parent = templateSeedDetails.SeedViewportFrame
local camera = Instance.new("Camera")
camera.Parent = templateSeedDetails.SeedViewportFrame
templateSeedDetails.SeedViewportFrame.CurrentCamera = camera
if seedClone.PrimaryPart then
local distance = seedClone:GetAttribute("CameraDistance")
camera.CFrame = CFrame.new(seedClone.PrimaryPart.Position + Vector3.new(0, distance / 2, distance), seedClone.PrimaryPart.Position)
end
task.spawn(function()
while true do
seedClone:SetPrimaryPartCFrame(seedClone.PrimaryPart.CFrame * CFrame.Angles(0, math.rad(1), 0))
task.wait(0.01)
end
end)
end
And this is the hierarchy to show exactly where the template is:
Now in the BuyScript, there is supposed to be some code to check if ChildAdded occurs on the ScrollingFrame, and then have the Buy Buttons work respectively. However, the script doesn’t work for some reason, so I’ve simplified it to just print a statement when ChildAdded occurs to try and troubleshoot the problem:
local parentInstance = script.Parent
parentInstance.ChildAdded:Connect(function(seedItem)
print(seedItem.Name .. " added to the " .. parentInstance)
end)
No matter how I approach this, this print statement doesn’t fire in the console, so what exactly am I missing here?