Trying to modify a chest that stores all tools a player puts in it, right now all the stored tools are able to be accessed by all players but I’m trying to make it where only the person that stored the tools can acces them.
I’ve never really used datastores so any help would be very much appreciated
I’ll include both the script that I’m trying to fix and the full model.
if script.Enabled.Value.Value == true then
local Folder = script.ToolsFolder
Folder.Parent = nil
local toolsExisting = {}
local dss = game:GetService("DataStoreService")
local Data = ""..script.Parent.Parent.Name.."-tools"
local toolsDS = dss:GetDataStore(Data)
local toolsFolder = Folder
local descendants = game:GetDescendants()
for index, descendant in pairs(descendants) do
if descendant:IsA("Tool") then
local Clone = descendant:Clone()
Clone.Parent = Folder
end
end
local getSuccess, data = pcall(function()
local toolsSaved = toolsDS:GetAsync(tostring(toolsDS))
if toolsSaved then
for i, toolSaved in pairs(toolsSaved) do
if toolsFolder:FindFirstChild(toolSaved) then
toolsFolder[toolSaved]:Clone().Parent = script.Chest.Value
end
end
else
end
end)
game:BindToClose(function()
toolsExisting = {}
for i, toolInChest in pairs(script.Chest.Value:GetChildren()) do
table.insert(toolsExisting, toolInChest.Name)
end
local success, errormsg = pcall(function()
toolsDS:SetAsync(Data, toolsExisting)
end)
if errormsg then warn(errormsg) end
end)
end
Tool storage.rbxm (27.4 KB)