Skip to content

Commit 3b10aff

Browse files
committed
make profile storage selection smart
1 parent 294cf12 commit 3b10aff

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

src/SaveMenu/Save.lua

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
local ChangeHistoryService = game:GetService("ChangeHistoryService")
2+
local CollectionService = game:GetService("CollectionService")
23
local ServerStorage = game:GetService("ServerStorage")
34
local Lighting = game:GetService("Lighting")
45

@@ -31,6 +32,29 @@ local function createProfile()
3132
return profileFolder
3233
end
3334

35+
local function determineParent()
36+
local parentCounts = {}
37+
38+
for _, profile in CollectionService:GetTagged("LightingProfile") do
39+
if not parentCounts[profile.Parent] then
40+
parentCounts[profile.Parent] = 1
41+
else
42+
parentCounts[profile.Parent] += 1
43+
end
44+
end
45+
46+
local highestCount = 0
47+
local commonParent = ServerStorage
48+
49+
for parent, count in parentCounts do
50+
if count > highestCount then
51+
commonParent = parent
52+
end
53+
end
54+
55+
return commonParent
56+
end
57+
3458
return function(props)
3559
local textBox = props.textBoxRef:getValue()
3660

@@ -53,7 +77,7 @@ return function(props)
5377
local profile = createProfile()
5478
profile.Name = profileName
5579
profile:AddTag("LightingProfile")
56-
profile.Parent = ServerStorage
80+
profile.Parent = determineParent()
5781

5882
ChangeHistoryService:SetWaypoint("Create lighting profile")
5983
end,

0 commit comments

Comments
 (0)