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