Before anything:
- I do not know how datastores work, I’ve tried to document myself from the official Roblox datastore documentation site but I barely understood anything.
- I know there’s a lot of posts about tool saving and a lot of Youtube videos about it, but for some reason, every tool saving datastore method that I’ve tried either doesn’t work at all or works a couple of times then it breaks. I have tried so many tool saving methods but all of them did not work and did not have what I require for my game.
I just need some help with this.
What I’d like to achieve:
- A datastore that saves the players Backpack upon leaving/resetting
- Does not break after a couple of tests
What have I tried:
I’ve tried a couple of datastore scripts but this is the latest one that I’ve tried
local toolFolder = game:GetService("ServerStorage"):FindFirstChild("SavedToolss")
local dataStoreSer = game:GetService("DataStoreService")
local saveData = dataStoreSer:GetDataStore("ToolSaverTest")
game.Players.PlayerAdded:Connect(function(Player)
local toolData = saveData:GetAsync(Player.UserId)
local backpack = Player:WaitForChild("Backpack")
local StarterG = Player:WaitForChild("StarterGear")
if toolData ~= nil then
for i, v in pairs(toolData) do
if toolFolder:FindFirstChild(v) and backpack:FindFirstChild(v) == nil and StarterG:FindFirstChild(v) == nil then
toolFolder[v]:Clone().Parent = backpack
toolFolder[v]:Clone().Parent = StarterG
end
end
end
Player.CharacterRemoving:Connect(function(Character)
Character:WaitForChild("Humanoid"):UnequipTools()
end)
end)
game.Players.PlayerRemoving:Connect(function(Player)
local toolTable = {}
for i,v in pairs(Player.Backpack:GetChildren()) do
table.insert(toolTable, v.Name)
end
if toolTable ~= nil then
saveData:SetAsync(Player.UserId, toolTable)
end
end)
This one only saves the tools whenever the player leaves, not when the player resets.
I just need some help with this because every post and Youtube video has been of no help.