Roblox Looting system not working

Yo, so basically im trying to make a looting system in which when a player dies, a part spawns on him and when someone interacts with the part they get the dead players tools.

local script in startercharacterscript:

local Player = game.Players.LocalPlayer
local Char = Player.Character
local tools = Player.Backpack:GetChildren()
Char:WaitForChild("Humanoid").Died:Connect(function()
	game.ReplicatedStorage.RemoteEvent:FireServer(tools)
end)

script in serverscriptservice:

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player, tools)
	local Character = player.Character
	local part = Instance.new("Part")
	part.Name = "Loot"
	part.CFrame = Character:FindFirstChild("HumanoidRootPart").CFrame
	part.Parent = game.Workspace
	local Proximity = Instance.new("ProximityPrompt", part)
	Proximity.Triggered:Connect(function(TheOneWhoTriggered)
		tools.Parent = TheOneWhoTriggered.Backpack
		part:Destroy()
	end)
end)

please help

LineOfSight could potentially be an issue. Try setting RequiresLineOfSight to false.

Also, can you see the part after it’s created? I noticed that you don’t modify anything about the part like Anchored, CanCollide, Transparency, etc.

yeah, i can see the part after its created.

Did disabling RequiresLineOfSight work for you?

nope, it didnt work sadly…fghfghfgh

Oh. It looks like you only use GetChildren() before they die, not once they actually die. I would also try to check for tools in the character as well.

i tried cloning the players backpack tools but i get

ServerScriptService.Script:4: attempt to call missing method ‘Clone’ of table

I’m not the smartest person, but I believe the issue is that you’re sending over a table of the player’s tools and then trying to assign that directly to the player’s backpack so I would try making a loop that goes through the table and assigns each tool to the player’s backpack one by one

You need to loop through all the objects inside the table.

for i,v in pairs(example_table) do
 v:Clone()
end
tools.Parent = TheOneWhoTriggered.Backpack

“tools” is a table, not an instance.

replace this line of code with

for _, v in tools do
    v.Parent = TheOneWhoTriggered.Backpack
end

edit: realized this just after posting, each tool would get deleted after the character died. you would have to clone each tool and parent it to ServerStorage or something

Alright so i did this:

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player)
	local backpack = player.Backpack
	local items = backpack:GetChildren()
	local replicated = game.ReplicatedStorage
	local foldernew = Instance.new("Folder")
	foldernew.Parent = replicated
	items.Parent = foldernew
	local part = Instance.new("Part")
	part.Name = "Loot"
	part.CFrame = player.Character:FindFirstChild("HumanoidRootPart").CFrame
	part.Parent = game.Workspace
	local Proximity = Instance.new("ProximityPrompt", part)
	Proximity.Triggered:Connect(function(TheOneWhoTriggered)
		for _, v in foldernew do
			v.Parent = TheOneWhoTriggered.Backpack
		end
		part:Destroy()
	end)
end)

and now everytime i interact with the part i get

ServerScriptService.Script:14: attempt to iterate over a Instance value

You need to loop through its children/descendants. e.g:

for _, v in foldernew:GetChildren() do
			v.Parent = TheOneWhoTriggered.Backpack
		end

i just realized that the main reason i dont get the tools is because im cloning them after death

Try something like this,

Server Script:

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player, tools)
	local Character = player.Character
	local part = Instance.new("Part")
	local toolfolder = Instance.new("Folder")
	toolfolder.Name = "toolfolder_"..player.Name
	toolfolder.Parent = game.ServerStorage
	for _, tools in tools do
		tools.Parent = toolfolder
	end
	part.Name = "Loot"
	part.CFrame = Character:FindFirstChild("HumanoidRootPart").CFrame
	part.Parent = game.Workspace
	local Proximity = Instance.new("ProximityPrompt", part)
	Proximity.Triggered:Connect(function(TheOneWhoTriggered)
		for _, tools in toolfolder:GetChildren() do
			tools.Parent = TheOneWhoTriggered.Backpack
		end
		part:Destroy()
		toolfolder:Destroy()
	end)
end)

Local Script:

local Player = game.Players.LocalPlayer
local Char = Player.Character
Char:WaitForChild("Humanoid").Died:Connect(function()
	local tools = Player.Backpack:GetChildren()
	game.ReplicatedStorage.RemoteEvent:FireServer(tools)
end)

i think its not a good idea to send itens from local to server… a exploiter can put how amount of itens that he wants in their backpack and the server will load all of these itens

i made some changes in your script
Server:

local function PickupItens(plr, toolfolder, part)
    for _, itens in toolfolder:GetChildren() do
        itens.Parent = plr.Backpack
    end
    part:Destroy()
    toolfolder:Destroy()
end

game.ReplicatedStorage.RemoteEvent.OnServerEvent.OnServerEvent:Connect(function(player)
    local tools = player.Backpack:GetChildren()
	local Character = player.Character

    if Character and tools then
        if Character:FindFirstChild("HumanoidRootPart") then
            local part = Instance.new("Part")

            local toolfolder = Instance.new("Folder")
            toolfolder.Name = `toolfolder_{player.Name}`
            toolfolder.Parent = game.ServerStorage
        
            for _, itens in tools do
                itens.Parent = toolfolder
            end
        
            part.Name = "Loot"
            part.CFrame = Character.HumanoidRootPart.CFrame
            part.Parent = game.Workspace

            local Proximity = Instance.new("ProximityPrompt")
            Proximity.Parent = part
            Proximity.Triggered:Connect(function(TheOneWhoTriggered)
                if TheOneWhoTriggered.Name ~= player.Name then
                    PickupItens(TheOneWhoTriggered, toolfolder, part)
                elseif TheOneWhoTriggered.Character then
                    local humanoid = TheOneWhoTriggered.Character:FindFirstChild("Humanoid")
                    if humanoid and humanoid.Health > 0 then
                        PickupItens(TheOneWhoTriggered, toolfolder, part)
                    end
                end
            end)
        end
    end
end)

LocalScript:

local Player = game:GetService("Players").LocalPlayer
local Char = Player.Character or Player.CharacterAdded:Wait()

Char:WaitForChild("Humanoid").Died:Connect(function()
	game.ReplicatedStorage.RemoteEvent:FireServer()
end)

bro trust me, there are barely any exploiters, ive never seen an exploiter in a hood-type game.

ok, but its not good to have bad habits

yeah i know, thank you for the help though!