I’m trying to develop a whole cosmetic system, and in the following local script inside of a gui everything works fine up to the print “Locals Created”, I’ve tried a bunch of different methods such as tostring, pairs, etc. but nothing works. It’s like I can’t clone anything or the for i, obj part doesn’t work. I don’t know whats going on and what I’m doing wrong.
local Services = {
ReplicatedStorage = game:GetService("ReplicatedStorage"),
Players = game:GetService("Players"),
DataStoreService = game:GetService("DataStoreService"),
}
local player = Services.Players.LocalPlayer
local CosmeticsFolder, PlayerData = Services.ReplicatedStorage:WaitForChild("Cosmetics"), Services.ReplicatedStorage:WaitForChild("PlayerData")
local cosmetics = PlayerData:WaitForChild(player.Name):WaitForChild("Cosmetics")
local ButtonPreset, objects = script.Parent.Parent.Stored:FindFirstChild("Button"), script.Parent.Objects
print("Locals Created.")
for i, obj: Accessory in ipairs(cosmetics:GetChildren()) do
print("New Object Found.")
local newObject = ButtonPreset:Clone()
local mainObject = CosmeticsFolder:FindFirstChild(obj.Name):Clone()
if mainObject then
newObject.Name = obj.Name
mainObject.Parent = newObject.Preset
newObject.Parent = objects
end
end
This part confuses me a bit. The obj variable is being typed as Accessory, but the cosmetics thing here is children of ReplicatedStorage.PlayerData.<player name>.Cosmetics. Are there actually Accessory instances in there, or are there or just some kind of placeholder like a value object with the accessory name? I ask because the structure suggests that the real Accessories are in ReplicatedStorage.Cosmetics. Some clarification is needed here about what’s actually in these locations.
There are 2 actual Accessory instances in the players data folder, both with separate names. They both also exists inside the Cosmetics folder child of ReplicatedStorage, every child of these folders are Accessories. But if you need any more clarification please let me know and on what exactly.
So I actually found the problem.
Apparently all the instances I was looking for inside the players data folder cosmetic folder were added after the ‘for i, obj’ part was ran, so what I did was I used the ChildAdded() and used the same logic inside of the for i, obj’ part.