Hi everyone!
I wanted to make a keep tools script, but the script(s) don't keep them in the backpack. I used 3 scripts, A module script, which has a table "list of items" in it, a server script which detects player deaths and attempts to put player tools back into their backpack, and a local script, which inserts a tool into the player's backpack and into the "list of items" table.
Here's the module script
local Main = {}
Main.Survivors = {} -- ignore this
Main.ListOfItems = {}
return Main
Here's the server script
local Main = require(game.Workspace.Main)
game:GetService('Players').PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
character:WaitForChild("Humanoid").Died:Connect(function()
print("Keep Tools Script: " .. player.Name .. " has died")
local listOfItems = Main.ListOfItems
print(listOfItems[1]) -- prints "nil"
print(listOfItems[1] == nil) -- prints "true"
player.CharacterAdded:Connect(function(Char)
for i = 1, #listOfItems do
local item = listOfItems[i]
local itemClone = item:Clone()
local player = game.Players:GetPlayerFromCharacter(Char)
itemClone.Parent = player.Backpack
print("Keep Tools Script: Successfully kept the " .. item .. " item!")
end
end)
end)
end)
end)
And here's the local script
local Main = require(game.Workspace.Main)
local Cost = 30
local Item = game.Lighting.GOTTIE
script.Parent.MouseButton1Down:Connect(function()
local player = game.Players.LocalPlayer
local Coins = player.leaderstats.Coins.Value
if Coins >= Cost and not player.Backpack:FindFirstChild("GOTTIE") then
Coins = Coins - Cost
player.leaderstats.Coins.Value = Coins
local ItemClone = Item:Clone()
ItemClone.Parent = player.Backpack
table.insert(Main.ListOfItems, #Main.ListOfItems + 1, Item)
print(Main.ListOfItems[1] == nil) -- prints "false"
print(Main.ListOfItems[1]) -- prints "GOTTIE"
end
end)
For some reason, the local script says that the item is in the "list of items" table, but the server script says otherwise. Aren't they supposed to be one or the other (nil or not nil)?
Any help is appreciated :)

2 comments
Oh ok! Thanks a lot for telling me this, I'll try it out!
Hey, why dont you put the tools into Player.StarterGear, that way Players wont lose the tools unless they leave, and you can use DataStores to prevent that from happening as well