Hello! I am currently stuck on how I can get object values to load correctly from my data serialization script. Here is the segment that I'm using. (I am using Collection Service to tag the parts that have been placed inside the Object Value's Value, and the primary part (that holds the object value))

local cs = game:GetService("CollectionService")
local playergarage = workspace.Garages:FindFirstChild(player.GarageName.Value)

local function GetOtherParts(part, tag)
	for _,v in pairs(playergarage.PlayerParts:GetChildren()) do
		if v.PrimaryPart ~= part then
			if cs:GetTags(v.PrimaryPart)[1] == tag then
				return v.PrimaryPart
			end
		end
	end
end

local saved = local saved = d:GetAsync(tostring(user.UserId))

if saved then --If data is saved 
	for _,v in pairs(workspace.Garages:FindFirstChild(user.GarageName.Value).PlayerParts:GetChildren()) do
		for i, data in pairs(saved) do
			local tag = tostring(data["tag"])
			if tag then
				cs:AddTag(v.PrimaryPart, tag)
				local tagged_parts = cs:GetTagged(tag)
				for _,p in pairs(tagged_parts) do
					if p:FindFirstChild("Config") then
						for _,c in pairs(p.Config:GetChildren()) do
							if c:IsA("ObjectValue") then
								local t = tostring(tag):split("/")
								--print(t[1], t[2], t[3])
								if c.Name == tostring(t[1]) then
									local part = GetOtherParts(p, tag)
									if not part then
										c.Value = GetOtherParts(p, tag)
									else
										c.Value = part
									end
								end
							end
						end
					end
				end
			end
		end
	end
end

Currently, it can only load one value correctly and not the others. Ex. (part with 4 object values, only one loads correctly and the other 3 dont)

I have a remote to Tag the parts, if it helps:

remotes.CreateTags.OnServerEvent:Connect(function(player, mainpart, selectedpart, objectvaluename)

local num = math.random(1000,10000) / 100
local tag = tostring(tostring(objectvaluename) .. "/" .. tostring(num)) -- divides both the name and the tag so it can be split between the "/" and assign the split[1] value to the part thats tagged with the split[2] tag
cs:AddTag(mainpart, tag)
cs:AddTag(selectedpart, tag)

end)

All (serious) help appreciated, thank you for your time!

1 comment