Help with NPC looting system

I have a looting system that drops a random set of tools from within a folder located in serverstorage when i kill an NPC. The only issue im having is that the NPC drops the same tools for every player. How can i make it so the NPC drops unique loot for each player? Or can anybody send me a link to any info on how to do this? I would really appreciate it.

-- variables (Made By Er_1x / ERIC#2073)
local hum = script.Parent -- humanoid
local tfolder = game:GetService("ServerStorage"):FindFirstChild("Pickups") -- finds the folder
local folderc = tfolder:GetChildren() -- gets the items on the folder

local IsModel = true -- check for model if its not a model leave it to false else set it to true
local IsRandom = true -- if set to false add a tool name to get the specific iten you want
local IsTool = false -- checks if its a tool or not IF IT IS A TOOL set it to true if not then flase
local ItemName = "" -- if israndom is set to true leave it blank

-- script part
hum.Died:Connect(function() -- function
	local randomRepeat = math.random(1, 2)
	for i = 1, randomRepeat do
		if IsRandom then
			if IsTool == false then
				local random = math.random(1, #folderc) -- randomizes
				local index = folderc[random] -- index the tool

				local item = index:Clone() -- clone the randomized tool
				item.Parent = game:GetService("Workspace") -- parent of the tool

				if IsModel == true then -- if it is a model or not dont change, only change the one on the variables
					item:MoveTo(hum.Parent.Head.Position) -- how we can move it because its a model
				else
					item.CFrame = hum.Parent.Head.CFrame -- cframe ( position of the tool)
				end

				print("Random Item Dropped: "..index.Name) -- notify
			else
				local random = math.random(1, #folderc) -- randomizes
				local index = folderc[random] -- index the item

				local tool = index:Clone() -- clone the randomized item
				tool.Parent = game:GetService("Workspace") -- parent of the item
				tool.Handle.CFrame = hum.Parent.Head.CFrame -- cframe ( position of the item)

				print("Random Tool Dropped: "..index.Name) -- notify
			end
		else -- if random is not in true
			if IsTool == false then
				local item = tfolder:FindFirstChild(ItemName):Clone() -- gets the tool ( finds the tool inside the folder
				item.Parent = game:GetService("Workspace") -- parent of the tool

				if IsModel == true then -- if it is a model or not dont change, only change the one on the variables
					item:MoveTo(hum.Parent.Head.Position) -- how we can move it because its a model
				else
					item.CFrame = hum.Parent.Head.CFrame -- cframe ( position of the tool)
				end

				print("Item Dropped: "..ItemName) -- notify
			else
				local tool = tfolder:FindFirstChild(ItemName):Clone() -- gets the tool ( finds the tool inside the folder
				tool.Parent = game:GetService("Workspace") -- parent of the tool
				tool.Handle.CFrame = hum.Parent.Head.CFrame -- cframe ( position of the tool)

				print("Tool Dropped: "..ItemName) -- notify
			end
		end
	end
end) -- end of function

Do you mean it drops the same tools for everyone on the server or every time someone kills it?

The NPC drops tools for every player within a certain distance when he is killed. He drops the same tools for each player within that range though. I don’t want that. I need each player to get a unique drop.

For example if he drops a sword and a fire axe, it drops those same tools on every players screen. I need each player to get a unique loot drop.

The reason why it would be the same for everyone on the server is because it is a server script that is calculated once, on the server. You would need to calculate it once per person and every time it has calculated for a person that you send that info to a client-sided tool displayer so it can drop those tools only for that specific person (otherwise it would drop all the random tools available to everyone in the vicinity).

note: make sure to not just “give” the client the ability to spawn tools whenever without a security check or it’ll be abused by exploiters

1 Like

Oh man, that’s a bit out of my league at the moment lol i rather just hire some help.