Model isn't spawning/parented to part

  1. What do you want to achieve?
    I’d like to have a random model from the Shop folder in replicated storage, parent itself to the ObjectDisplay part of each SpecialDisplay object in the workspace.

  2. What is the issue?
    The model only parented to the ObjectDisplay part for 1 SpecialDisplay object in the workspace, not all of the SpecialDisplay objects in the workspace.

Screen Shot 2023-04-02 at 11.04.54 PM

  1. What solutions have you tried so far?
    Tried rewriting the code multiple times for a few hours… no success ._.

Additional Info + ServerScript

local replicatedStorage = game:GetService("ReplicatedStorage")
local shopFolder = replicatedStorage:WaitForChild("Shop")
local workspace = game:GetService("Workspace")

-- Find all the SpecialDisplay objects in the workspace
local specialDisplays = workspace:GetDescendants()
for _, obj in ipairs(specialDisplays) do
	if obj.Name == "SpecialDisplay" then
		-- Find all the ObjectDisplay children of each SpecialDisplay1 object
		local objectDisplays = obj:GetDescendants()
		for _, child in ipairs(objectDisplays) do
			if child.Name == "ObjectDisplay" then
				-- Spawn a random model for each ObjectDisplay child
				local function spawnRandomModel()
					local models = shopFolder:GetChildren()
					if #models == 0 then
						print("There are no models in the shop folder.")
						return
					end

					local randomModelIndex = math.random(1, #models)
					local randomModel = models[randomModelIndex]
					local clonedModel = randomModel:Clone()

					-- Find the root part of the cloned model
					local rootPart = clonedModel.PrimaryPart.CFrame.Position

					-- Calculate the offset between the root part and the ObjectDisplay child
					local offset = child.Position - rootPart

					-- Parent the cloned model to the ObjectDisplay child and move it to the correct position
					clonedModel.Parent = child
					clonedModel:SetPrimaryPartCFrame(CFrame.new(child.Position)) --+ offset))
				end

				-- Spawn a random model immediately for each ObjectDisplay child
				spawnRandomModel()

				-- Spawn a new random model for each ObjectDisplay child every 30 minutes
				while true do
					wait(30 * 60)
					spawnRandomModel()
				end
			end
		end
	end
end

Let me know if you’d like me to provide additional info! Thank you for your help <3

It seems that at soon as something is put into the first display, this gets performed.

while true do
					wait(30 * 60)
					spawnRandomModel()
				end

Your code is pretty extra, instead I would use a for loop and add the model to each SpecialDisplay. Sorry I don’t know if thats what you’re talking about

yeah, I’d like the item to refresh every 30 minutes

I see. can you give me an example on how I would do this?

Sure. In this example I will use my own model thingy.

local part1 = game.Workspace.part1
local partGroups = game.Workspace.partGroups

while wait(30 * 60) do
  for i, v in pairs(partGroups) do
    local partClone = part1:Clone()
    partClone.Parent = v
  end
end

Sorry if confusing, tell me if you don’t understand.