-
What do you want to achieve? I want to know how to save data, but I don’t want it to save currency I want it to save for example a players inventory and the tools inside it
-
What is the issue? I dont know how to do it
Can we see the script you made so we know how we can help you?
This is the value
local df = ds:GetDataStore("PlayerExperience")
game.Players.PlayerAdded:Connect(function(player)
script.Parent.Value = df:GetAsync(player.UserId)
if script.Parent.Value == true then
local Clone = game.ReplicatedStorage.Part:Clone()
Clone.Parent = player.PlayerGui.Bottom.InventoryFrame.ScrollingFrame
end
end)
game.Players.PlayerRemoving:Connect(function(player)
df:SetAsync(player.UserId, script.Parent.Value)
end)```
This is the the ui
```lua
game.ReplicatedStorage.Events.Data.OnServerEvent:Connect(function(player)
local ds = game:GetService("DataStoreService")
local df = ds:GetDataStore("PlayerExperience")
local PL = game.Players:FindFirstChild(player.Name)
game.ServerStorage.Part1.Value = true
df:SetAsync(PL.UserId, game.ServerStorage.Part1.Value)
end)```
ok, so yo will saving an instance, so to do that you can save a table with tools name here is an example of how you can use this method
local dss = game:GetService("DataStoreService")
local toolsDS = dss:GetDataStore("ToolsData")
local toolsFolder = game.ServerStorage.ToolsFolder --A folder in sever storage with the tools you wanna save
game.Players.PlayerAdded:Connect(function(plr)
local toolsSaved = toolsDS:GetAsync(plr.UserId .. "-tools") or {}
for i, toolSaved in pairs(toolsSaved) do
if toolsFolder:FindFirstChild(toolSaved) then
toolsFolder[toolSaved]:Clone().Parent = plr.Backpack
toolsFolder[toolSaved]:Clone().Parent = plr.StarterGear
end
end
plr.CharacterRemoving:Connect(function(char)
char.Humanoid:UnequipTools()
end)
end)
game.Players.PlayerRemoving:Connect(function(plr)
local toolsOwned = {}
for i, toolInBackpack in pairs(plr.Backpack:GetChildren()) do
table.insert(toolsOwned, toolInBackpack.Name)
end
local success, errormsg = pcall(function()
toolsDS:SetAsync(plr.UserId .. "-tools", toolsOwned)
end)
if errormsg then warn(errormsg) end
end)
Alright so in my case I want to make ui save after you do something is there a way you can do that? Please help, thank you.
You should also be saving player data with individual threads on DataModel:BindToClose()
if you genuinely care about not losing data. Only saving when a player leaves is asking for data loss. It might require some edge-case work depending on when BindToClose fires compared to when the last Player disconnects.
yeah, but i’m giving to him an example so it should be added by himself
Oh wow, it said you where typing for like 5 minutes so ive been waiting to see if you responded to me but looks like not
yeah, srry
local Plrs = game:GetService("Players")
local DS = game:GetService("DataStoreService")
local Part = workspace.Part
Plrs.PlayerAdded:Connect(function(plr)
local data
local success, err = pcall(function()
data = DS:GetAsync(plr.UserId.."Key")
end)
if data then
for i, gui in pairs(data) do
for _, v in pairs(game.StarterGUI.ReplicatedUIS) do
if v.Name == gui then
gui:Clone.Parent = plr.PlayerGui.Wherever
end
end
end
end
end)
Part.Touched:Connect(function(hit)
local Data
if game.Players:GetPlayerFromCharacter(hit.Parent) then
local success, err = pcall(function()
Data = data = DS:GetAsync(plr.UserId.."Key")
end)
if not data then
DS:SetAsync(game.Players:GetPlayerFromCharacter(hit.Parent).UserId.."Key")
end
end
end)
basically here, you just put the gui you want to duplicate or idk and then with the data you just go in a loop trough the children of wherever you put the UIS in this example when you touch a part the data get saved
Do you have discord by any chance i wanna show you what im trying to do if you do add me: TinyFlair#0279
ok, i’m joso555#0574
tags, tags
Here’s a resource for storing instances inside DataStores: