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

How do u make drop precentage?

function Drop() 
local drops = {"something"}
local G = math.random(1, 1)
local Obj = game.Lighting:findFirstChild(drops[G]):Clone() 
Obj.Parent = game.Workspace
Obj.Handle.CFrame = script.Parent.Head.CFrame + Vector3.new(5,2,0)
script:remove()
end 


while true do 
	wait(.1) 
	if (script.Parent.Enemy.Health <1) then
		Drop() 
	end 
end



I want it to drop "something" as a 15% chance when you kill it, and it respawns, and you have to keep killing it, when it clones the "something" on drop, it is a 100% chance, can you fix this so it is a 15% chance. Please help.

1 answer

I assume Enemy is a Humanoid object. Rather than spam checking to see if it's dead, wait for it to die and then call Drop. In this case, you can also add the chance factor, as it won't be repeatedly called.

script.Parent.Enemy.Died:connect(function()
	if math.random()<=.15 then
		Drop()
	end
end)

Calling math.random() without any arguments returns a random decimal from 0 to 1.

1 comment

0

wow thx

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