Im trying to make a player data reset when they die but I cant figure it out because my tools remains in my inventory and not removed.
local Data = game:GetService("DataStoreService")
local datast= Data:GetDataStore("Data")
game:GetService('Players').PlayerAdded:Connect(function(plr)
local toolsOwned = {}
plr.CharacterAdded:Connect(function(character)
character:WaitForChild("Humanoid").Died:Connect(function()
local success, errormsg = pcall(function()
toolsDS:RemoveAsync(plr.UserId .. "-tools", toolsOwned)
end)
if errormsg then warn(errormsg) end
print("Tool Datawipe")
end)
end)
end)
RemoveAsync only takes one parameter, which will be the key to the datastore. So do :RemoveAsync(plr.UserId…“-tools”). You don’t need to include the toolsOwned table.
Your GetDataStore variable should be the same when calling your GetAsync function as well (Which I’m assuming is in a different script), and you should be using the same key provided when you check for any data inside the Player’s key
Can I see where you call the SetAsync() functions then? You could also add a couple print statements, preferably inside when the character dies if it prints correctly
game.Players.PlayerAdded:Connect(function(plr)
local toolsSaved = datast(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()
datast(plr.UserId .. "-tools", toolsOwned)
end)
if errormsg then warn(errormsg) end
end)