-- script inside the NPC 

local humanoid = script.Parent.Humanoid
local replicatedStorage = game:GetService("ReplicatedStorage")
local lootFolder = replicatedStorage.Loot
local dropChance = 100

local function onDeath()
	local randomChance = math.random(1, dropChance)
	if randomChance == 100 then
		local randomItem = lootFolder:GetChildren()[math.random(1, #lootFolder:GetChildren())]:Clone()
		local player = game.Players:GetPlayerFromCharacter(humanoid.Parent)
		if player then
			randomItem.Parent = player.Backpack
			local gui = Instance.new("ScreenGui", player.PlayerGui)
			local imageLabel = Instance.new("ImageLabel", gui)
			imageLabel.Size = UDim2.new(0, 200, 0, 200)
			imageLabel.Position = UDim2.new(0.5, -100, 0.5, -100)
			imageLabel.Image = randomItem.ImageId
			task.wait(3)
			gui:Destroy()
		end
	end
end

humanoid.Died:Connect(onDeath)
