I have a Loadout Selector GUI that gives the player the gun from the class that they choose. I'm not a pro scripter yet, so I don't know these things yet. I want to make it so that the player keeps the gun that they chose in their inventory after they die. Is there a script that will help me with this problem? Thanks.
✓ ANSWER ACCEPTED
How can I make a tool stay in someone's inventory after they die?
2 answers
✓ Accepted answer
Put a folder in server storage and call it ToolsFolder any tools you want to save duplicate them and put them inside the folder then inside server script service put in a script and type this:
local dss = game:GetService("DataStoreService")
local toolsDS = dss:GetDataStore("ToolsData")
local toolsFolder = game.ServerStorage.ToolsFolder
game.Players.PlayerAdded:Connect(function(plr)
local toolsSaved = toolsDS:GetAsync(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()
toolsDS:SetAsync(plr.UserId .. "-tools", toolsOwned)
end)
if errormsg then warn(errormsg) end
end)
1 comment
0
Thanks you so much bro I really appreciate this. You are the best. *BTW how did u learn to script? I'm not really sure if YouTube tutorials are the way to go or not.
Put the gun in starter gear not in player backpack
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
Maybe a script that can go in starter player scripts or something... idk
Place it into StarterGear.
put the item in StarterPack