This makes me wish i was good at scripting

I’m working on a RPG game and a big part of my game is looting NPC’s after you kill them. I have a working system already but the issue is that the tools the NPC drops is not unique to each player.

So basically, if 3 players are fighting an NPC and they kill him, i need the NPC to drop unique loot for each player which can only been seen locally so players can’t pick up each others loot.

I tried to figure it out, but it seems out of my league at the moment, but before i decide to pay someone to do it for me i just wanted to know the easiest way to go about doing such a thing.

This script is a server script which is where things start to go wrong off the bat, im not sure if i can even achieve what i want with a server script.

-- 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

This is how I would go about it. And it’s okay in this case to only use the Server script as it seems to me that the rewards are just tools. The best way to go about it is to have the server insert the tools directly into each player’s Backpack. If you wanted each player to be able to walk up and pick up their own sword without it being stolen, you’d need to involve a Client script in addition to the Server script.

First, insert a folder into Workspace. Name it Rewards. Don’t add anything to it. This will come in handy later.

In your server code, store all players who have dealt damage to the enemy in a table. Say, make a table called fighters and store it in that. Whenever a player attacks an enemy, create that table and insert their name into it. Whenever additional players join in, you can just add their names. table.insert(fighters, player.Name)

If you wanted the code to be more complicated and take into account how much damage each player did and reward them more or less based on how much they contributed, you could make it more complicated. But for now, it’s best to create the framework and then build off of it once it’s finished. So don’t jump too far ahead.

So, once the enemy dies, you could call a function that processes each player’s reward. You could call, say, processRewards() and pass the fighters table as a parameter. You could also pass the name of the tool they’ve won as a parameter.

Have processRewards() loop through the player names and clone the name of the tool and then parent it to each player’s Backpack. And that’s pretty much it.

Are you available for hire? Lol. I can script some things so far but nothing like that. That’s out of my league at the moment. I’m still watching scripting tutorials so im not quite at that level. I can try but i doubt i can achieve it.

You need to set the tools parents to workspace not Workspace. The difference is Workspace is a local workspace, and workspace is the global workspace, or the client’s workspace.

Really? So just changing it to lowercase?

I’m happily available for hire if you want. The idea for a client-sided script to allow each player to pick up their own tool is something I could pretty easily do. You can DM me if you wanna discuss that more.

1 Like

remember,

local Rng = Random.new():NextInteger(1, 5);

if you do this, the “Rng” value will always be the same,
so you have to Set the Rng every time you want something to be random.