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

Dropping items on chance?

Can someone help me to make a script that will drop items on chance after killing a NPC boss...

1 answer

Server script inside of NPC:

local humanoid = script.Parent:waitForChild("Humanoid",10)
local rootpart = script.Parent:waitForChild("HumanoidRootPart",10)

local item -- your item instance
local chance = 2 -- would be 50/50

repeat wait() until humanoid.Health<=0 -- or humanoid.Died:wait()
local r = math.random(1,chance)
if r==chance then
	local clone = item:clone()
	clone.Parent=workspace
	clone:findFirstChild("Handle").CFrame=rootpart.CFrame+Vector3.new(0,4,0)
end
wait()
script:destroy()
-- i didn't test it yet; but it should work

3 comments

0

camelCase was deprecated, please use TitleCase.

0

'FindFirstChild' does not replace the dot operator. Do not use it unless you're handling existence conflicts. Adding a timeout for 'WaitForChild' follows the same rules; if you're allowing the variables to be potentially nil, then you must confirm that they were successfully allocated before proceeding.

0

oh, thanks. really useful info ;D

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