Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make a npc give a item when killed?

Asked by 3 years ago
Edited 3 years ago

So I have been working on a rpg and I couldn't figure out how to make a npc when killed have a chance to give you a item like a sword.

I am using this code idk why it doesn't work I'm not getting any errors and I don't see any problems

local humanoid = script.Parent:FindFirstChild("Humanoid")
local rp = game:GetService("ReplicatedStorage")
local drop = rp.drop:FindFirstChild("Livingwood_Dagger")
local hr = script.Parent:FindFirstChild("HumanoidRootPart")

humanoid.Died:Connect(function()
    local dropChance = math.random(1, 2)
    if dropChance == 1 then
        local clone = drop:Clone()
        clone.Parent = workspace
        local Handle = clone:FindFirstChild("Handle")
        if Handle then
            Handle.CFrame = hr.CFrame
        end
    end
end)

edit I just noticed that it does drop but doesn't go into the players backpack

0
Hi where is the script located? sne_123456 439 — 3y
0
it is in the npc Bubble_GumRoblox 19 — 3y
0
Are you trying to make collectable loot or just loot that goes directly into your inventory Mathilinium 112 — 3y
0
well once you clone it you can make a touch event so if the player touches the dropped tem it gets cloned into the players backpack! sne_123456 439 — 3y
0
mathilinum yes loot that goes directly into your inventory Bubble_GumRoblox 19 — 3y

Answer this question