Trying to make a looting system

So I’m trying to make a looting system but can’t seem to figure it out. The first thing I want to do is spawn a backpack the second the player dies. After that, I want to create a folder, move the folder to replicatedstorage, then clone all the tools from the player’s backpack into the folder in replicatedstorage. once the player triggers the proximity prompt a sound will play. Once the sound is finished playing, I will clone all the tools in the folder to workspace in a specific position near where the player’s backpack dropped.

this is what I have so far:
this first script is for the backpack spawn which I put in starterplayerscripts

local humanoid = script.Parent:WaitForChild(“Humanoid”)
local torso = script.Parent:WaitForChild(“Torso”)
local players = game.Players
humanoid.Died:Connect(function()
local backpack = script.Parent.Parent.Backpack
local items = backpack:GetChildren()
local clone1 = items:Clone()
local storage = Instance.new(“Folder”)
storage.Parent = game.ReplicatedStorage
storage.Name = “tempitems”
clone1.Parent = storage
wait()

local clone2 = game.ReplicatedStorage.TacticalBackpack:Clone()
clone2.Parent = workspace
clone2.Position = torso.Position + Vector3.new(math.random(-5,5), 0, math.random(-5,5))

end)

The second script is placed in a model which is parented to replicatedstorage
there is also a proximity prompt inside of the model

local pp = game:GetService(“ProximityPromptService”)
SS = game:GetService(“ServerStorage”)
local sound = script.Parent.SearchingThroughBackpack
local proximityprompt = script.Parent.ProximityPrompt

proximityprompt.Triggered:Connect(function(Player)

sound:Play()
sound.Volume = 2
sound.Looped = false

wait(8.192) – The Length of the sound

local folder = game.ReplicatedStorage:FindFirstChild("tempitems")
local items = folder:GetChildren()


local clone = items:Clone()
wait()

clone.Parent = workspace
clone.Handle.CFrame = script.Parent.CFrame + Vector3.new(5,2,0)


game.ReplicatedStorage.tempitems:Destroy()
wait()
script.Parent:Destroy()

end)

1 Like

Make a folder inside ReplicatedStorage and add the tools inside it:

local Folder = Instance.new("Folder", game.ReplicatedStorage)

Player.Character.Humanoid:UnequipTools()

for i,v in pairs(Player.Backpack:GetChildren()) do
    local Object = v:Clone()
    Object.Parent = Folder
end

Should I be using normal scripts or local scripts?

Normal script

To get Player just make a Player.Added:Connect(function(Player)) function

edit: or you can use remote events and then use a local script to check when the player dies and send it to a server script to get the player’s tools by sending the player’s name through the event.

So would it look something like this?

local humanoid = script.Parent:WaitForChild(“Humanoid”)
local torso = script.Parent:WaitForChild(“Torso”)
local players = game.Players

Player.Added:Connect(function(Player)
humanoid.Died:Connect(function()

local folder = Instance.new("Folder", game.ReplicatedStorage)
Player.Character.Humanoid:UnequipTools()

for i,v in pairs(Player.Backpack:GetChildren()) do
	local Object = v:Clone()
	Object.Parent = folder
end

folder.Name = "tempitems"

wait()

local clone2 = game.ReplicatedStorage.TacticalBackpack:Clone()
clone2.Parent = workspace
clone2.Position = torso.Position + Vector3.new(math.random(-5,5), 0, math.random(-5,5))

end)

end)

Yea that looks perfect! All the tools will be stored inside the folder and you can just make the player get all the items from that folder and if you have a despawn thing just delete that folder.

So just to make sure, when the player dies all their tools will be added to that folder?

Well not really you just have to make a wait script:

while wait() do
    if Player.Health <= 0 then
         --Do all the stuff
        break
    end
end)

Would I also do

local player = game.Players.LocalPlayers

at the beginning?

yea that is how you get the player your looking for

One more question. Should I keep this in starterplayerscripts or place it in startercharacterscripts

StarterGui is a great place to store LocalScripts!

This still didn’t end up working.

Here is a video from one of my other games that I made. I created a looting system for npc’s. But I was wondering how you would do this for players.

here is another video showing how it works in-game instead of me clicking run.

(Currently, nothing drops out of the bag because I need to finish making the tool models)

I hope this example helps.

Did you just kill a player or an NPC? Because NPC Don’t have the backpack function like players.

I killed an NPC. also, I know. But I was asking how to replicate this effect when killing a player.

In a local script if the player dies just make the same backpack thing drop and when you search it all the items in that folder that you saved the dead players tools drop around it.

I didn’t really wanna do this. But I think i might have to switch to a random loot table instead of trying to copy everything the player who died had. Thanks for the help though I really appreciate it!

Oh okay. Good luck with that then!

Thanks. Have a good rest of your day?
maybe it’s night I’m not really sure lol.

It’s Day time but hope for you aswell.

1 Like