Long story short, I have collectibles in my game and I’m using StreamingEnabled. The game can only reference the collectible models if the ‘ModelStreamingMode’ is set to ‘Persistent’. The issue with this is that I will have 48 collectibles in my game constantly persisting/being loaded.
I’m using DataStores to save player data across 3 different ‘save files’. I’d like to make it so that when the player loads into a save file, the ‘golden toast’ collectibles are updated to be slightly transparent, indicating that the player has already collected that collectible.
My code ‘works’ but errors if the collectible models are not ‘Persistent’. The code for setting the collectible to semi-transparent is happening on the Client, not the server. However, the game is single-player, thus I could technically do it on the server as well, but that’s not a great solution either I think.
I also have various worlds/levels the player can go to, if I could set models to persistent on runtime based on what world the player is in, that’d be awesome. But, that doesn’t seem to be a thing.
It’s not a coding issue per-say as it all works fine when the models are ‘Persistent’, but that isn’t good for my games performance. Hope that all makes sense.
I can provide code, but it wouldn't make sense without a bunch of other stuff that would be ~2,000 lines of code. Here's this anyways though:
function updateGoldenToastCollectionUI()
--print("Golden Toast Test 3")
if currentSaveFilePlayerIsPlayingOn.Value == "SaveFile1" then
local listOfWorldBasedGoldenToastCollected_Folder = game.Players.LocalPlayer:WaitForChild("playerDataFolder").saveFile1_TableFolder.collectiblesCollectedTableFolder.listOfWorldBasedGoldenToastCollected_Folder
local worldFoldersList = listOfWorldBasedGoldenToastCollected_Folder:GetChildren()
--print(worldFoldersList)
for i, worldFolder in pairs(worldFoldersList) do
local boolValues = worldFolder:GetChildren()
--print(boolValues)
for i, boolValue in pairs(boolValues) do
local goldenToastUIForThisBoolValue = WorldBasedCollectiblesFrame:WaitForChild(worldFolder.Name):WaitForChild(boolValue.Name)
local goldenToastFolderFromWorldThisCollectibleIsIn = InGame_Collectibles_Folder:WaitForChild(worldFolder.Name):WaitForChild("GoldenToast_Folder")
for i, goldenToastObjectModel in pairs(goldenToastFolderFromWorldThisCollectibleIsIn:GetChildren()) do
local goldenToastObjectModelIDNumber = goldenToastObjectModel:WaitForChild("collectibleNumberOutOfTotalInSpecificWorld_NumberValue")
local collectedStringPlusIDNumber = "Collected"..tostring(goldenToastObjectModelIDNumber.Value)
--print(boolValue.Name,collectedStringPlusIDNumber)
if boolValue.Name == collectedStringPlusIDNumber then
--print("HALLO?!")
if boolValue.Value == true then
-- player collected this golden toast
goldenToastUIForThisBoolValue.ImageColor3 = Color3.fromRGB(255,255,255)
goldenToastObjectModel:WaitForChild("goldenToastMesh").Transparency = 0.35
elseif boolValue.Value == false then
goldenToastUIForThisBoolValue.ImageColor3 = Color3.fromRGB(0,0,0)
goldenToastObjectModel:WaitForChild("goldenToastMesh").Transparency = 0
end
goldenToastObjectModel:WaitForChild("collectedBoolValue").Value = boolValue.Value
end
end
end
end
elseif currentSaveFilePlayerIsPlayingOn.Value == "SaveFile2" then
local listOfWorldBasedGoldenToastCollected_Folder = game.Players.LocalPlayer:WaitForChild("playerDataFolder").saveFile2_TableFolder.collectiblesCollectedTableFolder.listOfWorldBasedGoldenToastCollected_Folder
local worldFoldersList = listOfWorldBasedGoldenToastCollected_Folder:GetChildren()
for i, worldFolder in pairs(worldFoldersList) do
local boolValues = worldFolder:GetChildren()
--print(boolValues)
for i, boolValue in pairs(boolValues) do
local goldenToastUIForThisBoolValue = WorldBasedCollectiblesFrame:WaitForChild(worldFolder.Name):WaitForChild(boolValue.Name)
local goldenToastFolderFromWorldThisCollectibleIsIn = InGame_Collectibles_Folder:WaitForChild(worldFolder.Name):WaitForChild("GoldenToast_Folder")
for i, goldenToastObjectModel in pairs(goldenToastFolderFromWorldThisCollectibleIsIn:GetChildren()) do
local goldenToastObjectModelIDNumber = goldenToastObjectModel:WaitForChild("collectibleNumberOutOfTotalInSpecificWorld_NumberValue")
local collectedStringPlusIDNumber = "Collected"..tostring(goldenToastObjectModelIDNumber.Value)
--print(boolValue.Name,collectedStringPlusIDNumber)
if boolValue.Name == collectedStringPlusIDNumber then
--print("HALLO?!")
if boolValue.Value == true then
-- player collected this golden toast
goldenToastUIForThisBoolValue.ImageColor3 = Color3.fromRGB(255,255,255)
goldenToastObjectModel:WaitForChild("goldenToastMesh").Transparency = 0.35
elseif boolValue.Value == false then
goldenToastUIForThisBoolValue.ImageColor3 = Color3.fromRGB(0,0,0)
goldenToastObjectModel:WaitForChild("goldenToastMesh").Transparency = 0
end
goldenToastObjectModel:WaitForChild("collectedBoolValue").Value = boolValue.Value
end
end
end
end
elseif currentSaveFilePlayerIsPlayingOn.Value == "SaveFile3" then
local listOfWorldBasedGoldenToastCollected_Folder = game.Players.LocalPlayer:WaitForChild("playerDataFolder").saveFile3_TableFolder.collectiblesCollectedTableFolder.listOfWorldBasedGoldenToastCollected_Folder
local worldFoldersList = listOfWorldBasedGoldenToastCollected_Folder:GetChildren()
for i, worldFolder in pairs(worldFoldersList) do
local boolValues = worldFolder:GetChildren()
--print(boolValues)
for i, boolValue in pairs(boolValues) do
local goldenToastUIForThisBoolValue = WorldBasedCollectiblesFrame:WaitForChild(worldFolder.Name):WaitForChild(boolValue.Name)
local goldenToastFolderFromWorldThisCollectibleIsIn = InGame_Collectibles_Folder:WaitForChild(worldFolder.Name):WaitForChild("GoldenToast_Folder")
for i, goldenToastObjectModel in pairs(goldenToastFolderFromWorldThisCollectibleIsIn:GetChildren()) do
local goldenToastObjectModelIDNumber = goldenToastObjectModel:WaitForChild("collectibleNumberOutOfTotalInSpecificWorld_NumberValue")
local collectedStringPlusIDNumber = "Collected"..tostring(goldenToastObjectModelIDNumber.Value)
--print(boolValue.Name,collectedStringPlusIDNumber)
if boolValue.Name == collectedStringPlusIDNumber then
--print("HALLO?!")
if boolValue.Value == true then
-- player collected this golden toast
goldenToastUIForThisBoolValue.ImageColor3 = Color3.fromRGB(255,255,255)
goldenToastObjectModel:WaitForChild("goldenToastMesh").Transparency = 0.35
elseif boolValue.Value == false then
goldenToastUIForThisBoolValue.ImageColor3 = Color3.fromRGB(0,0,0)
goldenToastObjectModel:WaitForChild("goldenToastMesh").Transparency = 0
end
goldenToastObjectModel:WaitForChild("collectedBoolValue").Value = boolValue.Value
end
end
end
end
end
end