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

How do u make drop precentage?

Asked by 9 years ago
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

Log in to vote
0
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
9 years ago

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.

0
wow thx KFCPhoeyu 41 — 7y
Ad

Answer this question