so in my game if a player leaves when they are combat tagged they get a datastore value which is true and once they join again it will check if the value is true then proceed to not load in the saved tools and delete them but it dont work ofc
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local Tools = ServerStorage.Tools
local CombatTagList = ServerStorage.PlayerList.CombatTagged
local DataStore2 = require(ServerStorage.Modules.DataStore2)
DataStore2.Combine("Data","Backpack")
DataStore2.Combine("Data","CombatLog")
function savetools (player,BackpackStore,bool)
local Tools = {}
if bool == true then
if player.Character:FindFirstChildWhichIsA("Tool") and player.Character:FindFirstChildWhichIsA("Tool").CanBeDropped == true then
table.insert(Tools,player.Character:FindFirstChildWhichIsA("Tool").Name)
end
for i,v in pairs(player.Backpack:GetChildren()) do
if v.CanBeDropped == true then
table.insert(Tools,v.Name)
end
end
else
for i,v in pairs(player.Backpack:GetChildren()) do
if v.CanBeDropped == true then
table.insert(Tools,v.Name)
end
end
end
BackpackStore:Set(Tools)
end
Players.PlayerRemoving:Connect(function(player)
local CombatLogStore = DataStore2("CombatLog",player)
if CombatTagList:FindFirstChild(player.Name) then
CombatLogStore:Set(true)
print(CombatLogStore:Get())
end
end)
Players.PlayerAdded:Connect(function(player)
local BackpackStore = DataStore2("Backpack",player)
local CombatLogStore = DataStore2("CombatLog",player)
print(BackpackStore:Get(),CombatLogStore:Get())
if BackpackStore:Get() ~= nil then
if CombatLogStore:Get() == true then
print("clogged")
BackpackStore:Set(nil)
CombatLogStore:Set(false)
else
local PlayerTools = BackpackStore:Get()
for i = 1,#PlayerTools do
if Tools:FindFirstChild(PlayerTools[i],true) then
Tools:FindFirstChild(PlayerTools[i],true):Clone().Parent = player.Backpack
end
end
end
end
player.Backpack.ChildAdded:Connect(function(child)
savetools(player,BackpackStore,true)
end)
player.Backpack.ChildRemoved:Connect(function(child)
savetools(player,BackpackStore,false)
end)
end)