Hi, I’m making a tool save with datastore2, because Roblox’s data store can cause data loss and I don’t want that. I tried to make it but it is not working, here’s the code:
Tool Giver Code:
local ds2 = require(game.ServerScriptService.MainModule);
script.Parent.ClickDetector.MouseClick:Connect(function(plr)
local data = ds2("tools", plr)
game.ReplicatedStorage.Tool:Clone().Parent = plr.Backpack
ds2:Set(game.ReplicatedStorage.Tool.Name, true)
end)
Player Added Script:
local ds2 = require(game.ServerScriptService.MainModule);
game.Players.PlayerAdded:Connect(function(plr)
local tools = {};
local toolStore = ds2("tools", plr);
local function onUpdate(newtool)
table.insert(tools,newtool);
end
toolStore:OnUpdate(onUpdate);
for _, v in pairs(tools) do
game.ReplicatedStorage[v]:Clone().Parent = plr.Backpack
end
end)