Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make an npc monster give items to the player when killed?

i am not completely sure on how to do this. I would need a math.random in it somewhere to make sure it doesnt always give the item when killed right but how would i get the player/character that killed the monster - that would be a objectvalue named creator? however i only know how to do that with a leaderstats with money. how would i give the item to the player


local plr = game.Players.LocalPlayer


script.Parent.Handle.Touched:connect(function(hit)
if hit.Parent.Name == 'DroolingZombie' or 'Zombie' then
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    if plr then
        local tag = Instance.new('ObjectValue',hit.Parent.Humanoid)
        tag.Name = 'creator'
        tag.Value = plr
        wait(3)
        tag:Destroy()
	end
end

end)

this is the code in the sword

1 answer

✓ Accepted answer

It's pretty much the same process, however, you are just working with a tool. So you would need to clone the tool and parent it to the player's backpack.

If it is a random tool, then you would have a table of all the tools that you want to be able to drop, and randomly select one.

Example:

local tools = {"sword", "gun", "bow"} -- Strings as an example

local selectedTool = math.random(1, #tools) -- Selects a random element in the table (#tools is the size of the table, in this case tools)

print(tools[selectedTool])

dont really know what else to say lol

This discussion is preserved as it was. New answers, comments, and votes are closed.