Children not being replicated ((or represented)) as GUI properly

So to start off, I am making a trunk script for my game, the idea is It would be streamlined for all vehicles in the game with the part called “trunk”, and the purpose is storing crates.

What do you want to achieve? for it to replicate properly and show the player all the crates upon accessing the trunk

What is the issue? The initial method was upon clicking store, crate would be deleted and “converted” as a non physical instance with information about the crate as a child of the vehicle model, and would be read off as gui buttons for the player. the issue is it does not replicate properly, either it spams an unfathomable amount of crates at times or doesn’t do anything it is pretty inconsistent with its behaviour I re-wrote it some many times to avoid past mistakes.

I tried a rudimentary method of writing it, then tried to use tables but neither of which worked properly, even had the same issues except table insertion gave me request errors

What solutions have you tried so far? Looked on the hub, and at other sources, no luck yet

This is the code piece responsible for finding and storing ((local))

storeButton.MouseButton1Click:Connect(function()

					if character:FindFirstChild("Crate") and #cargoItems < folderAttributeCapacity then

						local playersCrate = character.Crate

						local crate = character:FindFirstChild("Crate")

						local desAtt = crate:GetAttribute("Destination")
						local courierAtt = crate:GetAttribute("Spawner")
						local valueAtt = crate:GetAttribute("Value")

						storeCrate:FireServer(playersCrate, slotFolder, desAtt, courierAtt, valueAtt)

					elseif character:FindFirstChild("Crate") and #cargoItems > folderAttributeCapacity then

						capCrate.Visible = true
						wait(3)
						capCrate.Visible = false

					end
					if not character:FindFirstChild("Crate") then
						warnCrate.Visible = true
						wait(3)
						warnCrate.Visible = false
					end
				end)
				
				local function trunkcrateToButton()
					for _, carCrate in pairs(slotFolder:GetChildren()) do
						
						if carCrate:IsA("Configuration") then
							
							local desAtt = carCrate:GetAttribute("Destination")
							local courierAtt = carCrate:GetAttribute("Spawner")
							local valueAtt = carCrate:GetAttribute("Value")
							
							local newButton = crateButton:Clone()
							newButton.Parent = storageList
							newButton:SetAttribute("Destination", desAtt)
							newButton:SetAttribute("Courier", courierAtt)
							newButton:SetAttribute("Value", valueAtt)
							newButton.deLabel.Text = tostring(desAtt)
							
							newButton.MouseEnter:Connect(function()
								hoverMoney.Text = "Value: $" ..tostring(valueAtt)
								hoverDestination.Text = "Destination: " ..tostring(desAtt)
								hoverCourier.Text = "Courier: " ..tostring(courierAtt)
								hoverUI.Visible = true
								UserInputService.InputChanged:Connect(function(input)
									if input.UserInputType == Enum.UserInputType.MouseMovement then
										local mousePosition = input.Position
										hoverUI.Position = UDim2.new(0, mousePosition.X*0.5, 0, mousePosition.Y)
									end
								end)
							end)
							newButton.MouseLeave:Connect(function()
								hoverMoney.Text = "Value: $"
								hoverDestination.Text = "Destination: "
								hoverCourier.Text = "Courier: "
								hoverUI.Position = UDim2.new(0.5, -hoverUI.AbsoluteSize.X/2, 0.5, -hoverUI.AbsoluteSize.Y/2)
								hoverUI.Visible = false
							end)
							
							newButton.MouseButton1Click:Connect(function()
								print(newButton)
								print(newButton.MouseButton1Click)
								
								local cratePos = trunk.Position + Vector3.new(0, 0, 5)
								newButton:Destroy()
								SpawnCrateEvent:FireServer(cratePos, carCrate, desAtt, courierAtt, valueAtt)

							end)
							
						end
					end
				end
				slotFolder.ChildAdded:Once(trunkcrateToButton)

please keep in mind i am using Zone+ for the detection and grouping of “trunks”

last but not least, I do not know how efficient what i am trying to do is. I am open to ideas or a possible fix, as always thank you to everyone helping in advance.

1 Like

try moving the trunkcrateToButton() function as it is being remade every time you press the store button

1 Like

it does nothing, or are you refering to the child added? i moved both and tested without child added and still no change or shows me no gui’s

I was mentioning it as it can cause a memory leak or a task being repeated to many times

1 Like

I see, thank you firstly i need to properly make it function

1 Like