Can someone help me to make a script that will drop items on chance after killing a NPC boss...
COMMUNITY QUESTION
Dropping items on chance?
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
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
camelCase was deprecated, please use TitleCase.
'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.
oh, thanks. really useful info ;D