RPG NPC Loot Help

So, I am making an RPG game using Lootplan for the NPC loot, and I tried giving the loot directly to the player then realized it was out of my skill range. Now I am trying to make the loot clone into Workspace where the NPC was killed for the player to pick up.
Here is my script so far

local LootPlan = require(game.ReplicatedStorage.LootPlan)
local ItemPlan = LootPlan.new("single")

-- The first argument is the name, the second is the chance
ItemPlan:AddLoot("Apple of Healing",99)
ItemPlan:AddLoot("Nothing",1)

local Humanoid = script.Parent.Humanoid
local ItemType = ItemPlan:GetRandomLoot()
function Dead()
	-- Where i need the script to go
end
Humanoid.Died:Connect(Dead)

I don’t know how to clone it to the NPC position after being killed, any suggestions? Also, this is a normal script and the high chances are for testing. All NPCs are named “Npc”

2 Likes

I don’t know what LootPlan is but I get the idea you are trying to achieve. Is “Apple of Healing” an object you want to place into the Workspace for the Player to pickup and place in their Backpack?
If yes, then you simply need to make a clone of the item from storage and sets it’s Position property to that of the HumanoidRootPart in the Dead() function:

local appleOfHealing = <location of your apple in the game>
...
function Dead()
	local appleClone = appleOfHealing:Clone()		-- make a copy of your apple from storage
	appleClone.Position = Humanoid.Parent.HumanoidRootPart.Position		-- set it's position to the of the HRP. If NPC has no HRP, then set it to another Part of the NPC
	appleClone.Parent= workspace		-- parent it to the game environment
end

If you wanted to place the item into the Player Backpack, then you would need to identify who killed the Humanoid which becomes slightly more difficult. Your weapon would need to Tag the NPC on a Hit event with the name of the Player as a value. Then when the NPC dies, read the Tag value of the Player and then clone the item to the Players backpack. This only works if the item being Cloned is a Tool, but the same caveat applies to the above.

So I tried modifying your script a bit to fit with Lootplan but its now saying position isn’t a valid member of Tool “Workspace.Apple of Healing”

local LootPlan = require(game.ReplicatedStorage.LootPlan)
local ItemPlan = LootPlan.new("single")

-- The first argument is the name, the second is the chance
ItemPlan:AddLoot("Apple of Healing",99)
ItemPlan:AddLoot("Nothing",1)

local Humanoid = script.Parent.Humanoid
local ItemType = ItemPlan:GetRandomLoot()

local ReplicatedStorage = game:GetService("ReplicatedStorage")

function Dead()
	if ItemType ~= "Nothing" then
		local apple = ReplicatedStorage.Tools:FindFirstChild("Apple of Healing"):Clone()		-- make a copy of your apple from storage
		apple.Parent = game.Workspace		-- parent it to the game environment
		apple.Position = Humanoid.Parent.HumanoidRootPart.Position		-- set it's position to the of the HRP. If NPC has no HRP, then set it to another Part of the NPC
	end
end
Humanoid.Died:Connect(Dead)

Any suggestions?

Is your apple a Model? If yes, then you need to set the PrimaryPart. For example:
image

It is a tool with a Handle and a script so I don’t know why it is doing this. I put the tools in a folder named “Tools” in ReplicatedStorage

Okay after a few minutes i figured it out. I didn’t really feel like working on it the other day but all i had to do was move the handle of the tool instead of the tool itself. Thanks for the help!