I’m making a game inspired by Dandy’s world, and i want to save the inventory system i made, it’s made by a bunch of buttons that you can click to equip the character, how can i save all the buttons and then paste into the new character list frame from the data store?
Here’s my current explorer:
Here’s the script that handles the change character event:
local CharacterEvent = game.ReplicatedStorage:WaitForChild("Events").CharacterEvent
local Characters = game.ReplicatedStorage:WaitForChild("Characters")
local Animators = game.ReplicatedStorage:WaitForChild("Animators")
CharacterEvent.OnServerEvent:Connect(function(Player, Button)
local Character = Characters:FindFirstChild(Button.Name)
local CharacterClone = Character:Clone()
local Animate = Animators:FindFirstChild(Button.Name):Clone()
local CharacterImageClone = game.ReplicatedStorage.CharacterImage:Clone()
if not Player.PlayerGui.InventoryUI.CharacterFrame.CharacterList:FindFirstChild(Character.Name) then
CharacterImageClone.Parent = Player.PlayerGui.InventoryUI.CharacterFrame.CharacterList
CharacterImageClone.Image = "rbxassetid://"..Character:GetAttribute("CharacterImage")
CharacterImageClone.Name = Button.Name
else
CharacterImageClone:Destroy()
end
print(Button.Name)
if game.StarterPlayer:FindFirstChild("StarterCharacter") then
game.StarterPlayer:FindFirstChild("StarterCharacter"):Destroy()
end
CharacterClone.Name = "StarterCharacter"
CharacterClone.Parent = game.StarterPlayer
task.wait(0.5)
Player:LoadCharacter()
if Player.Character:FindFirstChild("Animate") then
Player.Character:FindFirstChild("Animate"):Destroy()
end
Animate.Parent = Player.Character
CharacterEvent:FireClient(Player, Character)
end)
Hey!
I think if you want to store something which is not a value, then serialize it. Store the most important properties, etc. as you cannot save such things like gui.
For example:
If you want to convert a TextLabel, you can make a table to be stored, name it and add all of the important properties and all that.
I hope you understand!
So yk that you can’t store instances right?
Just convert those instances so that a datastore can actually save that. Since you want to save the buttons, just save those important properties like size, color, text, image, etc. Make your datastore organized as well and make sure that those values which got converted can be bought back into original form for you to use when accessing the datastore.
(Sry for not explaining properly)
So you mean that (this code is super work in progress) This will not work?
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("NoodlesDataStore")
local TableToStore = {}
function SaveData(Player, StoreStuff)
end
game.Players.PlayerAdded:Connect(function(Player)
Player.PlayerGui.InventoryUI.CharacterFrame.CharacterList.Changed:Connect(function()
for i, v in pairs(Player.PlayerGui.InventoryUI.CharacterFrame.CharacterList:GetChildren()) do
if v:IsA("GuiButton") then
table.insert(v)
end
end
end)
end)
For example, instead of directly adding the button to the DataStore like what you did here:
if v:IsA("GuiButton") then
table.insert(v)
end
You can do something like this:
if v:IsA("GuiButton") then
local ButtonTable = {}
table.insert(ButtonTable, v.Name)
table.insert(ButtonTable, v.Text)
--etc.. Instead replace with the properties you need to store inside the table. Store the table inside the DataStore btw.
end
Hmmm, oh and i forgot to say, i’m not that good in datastores, like i know just how to store values and that’s it, i even needed to watch a tutorial, so uhhhh, i need to learn more about datastores…
Yes, I was like you and I personally hate datastores honestly.
You must also take things like security and multiserver editting cuz you never want to lose player data right?
I recommend instead of you making datastores look into something like a external module (ProfileService, DataStore v2). There are multiple tutorials on this and I use something like this with ProfileService:
Look into those and also look into methods of serialization. Just searching it up will bring tons of videos and forums!
-- ProfileTemplate table is what empty profiles will default to.
-- Updating the template will not include missing template values
-- in existing player profiles!
local ProfileTemplate = {
Cash = 0,
Items = {},
LogInTimes = 0,
}
----- Loaded Modules -----
local ProfileService = require(game.ServerScriptService.ProfileService)
----- Private Variables -----
local Players = game:GetService("Players")
local ProfileStore = ProfileService.GetProfileStore(
"PlayerData",
ProfileTemplate
)
local Profiles = {} -- [player] = profile
----- Private Functions -----
local function GiveCash(profile, amount)
-- If "Cash" was not defined in the ProfileTemplate at game launch,
-- you will have to perform the following:
if profile.Data.Cash == nil then
profile.Data.Cash = 0
end
-- Increment the "Cash" value:
profile.Data.Cash = profile.Data.Cash + amount
end
local function DoSomethingWithALoadedProfile(player, profile)
profile.Data.LogInTimes = profile.Data.LogInTimes + 1
print(player.Name .. " has logged in " .. tostring(profile.Data.LogInTimes)
.. " time" .. ((profile.Data.LogInTimes > 1) and "s" or ""))
GiveCash(profile, 100)
print(player.Name .. " owns " .. tostring(profile.Data.Cash) .. " now!")
end
local function PlayerAdded(player)
local profile = ProfileStore:LoadProfileAsync("Player_" .. player.UserId)
if profile ~= nil then
profile:AddUserId(player.UserId) -- GDPR compliance
profile:Reconcile() -- Fill in missing variables from ProfileTemplate (optional)
profile:ListenToRelease(function()
Profiles[player] = nil
-- The profile could've been loaded on another Roblox server:
player:Kick()
end)
if player:IsDescendantOf(Players) == true then
Profiles[player] = profile
-- A profile has been successfully loaded:
DoSomethingWithALoadedProfile(player, profile)
else
-- Player left before the profile loaded:
profile:Release()
end
else
-- The profile couldn't be loaded possibly due to other
-- Roblox servers trying to load this profile at the same time:
player:Kick()
end
end
----- Initialize -----
-- In case Players have joined the server earlier than this script ran:
for _, player in ipairs(Players:GetPlayers()) do
task.spawn(PlayerAdded, player)
end
----- Connections -----
Players.PlayerAdded:Connect(PlayerAdded)
Players.PlayerRemoving:Connect(function(player)
local profile = Profiles[player]
if profile ~= nil then
profile:Release()
end
end)
Haha
Use a tutorial here as I cant fully explain this in details. All I know is that these functions go inside of a script called:
These functions connect the Profile Service, and it is like the connection hub for profile service.
I recommend you use a vid tho as the documentation tutorials on ProfileService is pretty confusing especially for beginners.
There are TONS of videos out there, so you can use those