Hey, I’m trying to make a chance system but whenever something is picked, it prints everything below it aswell:
function GetRandomOre()
local sum = 0
for orename, chance in pairs(oretable) do
sum += chance
end
local randomnumber = math.random(sum)
for orename, chance in pairs(oretable) do
if randomnumber <= chance then
print(orename)
end
randomnumber -= chance
end
end
function GetRandomOre()
local sum = 0
for orename, chance in pairs(oretable) do
sum += chance
end
local randomnumber = math.random(sum)
for orename, chance in pairs(oretable) do
if randomnumber <= chance then
print(orename)
end
randomnumber -= chance
return orename
end
end
I just want to print the ore selected, each ore has a different chance and everytime the function GetRandomOre is running, I want to get only one result. So in this case Common has a 60% chance of being chosen, Uncommon 30% and Rare 10%
Alright, so if you wanted to JUST print the object it selected, then once it selects and object, return the object it selected. If you don’t want it to stop all the code in the function, then just type “break”
function GetRandomOre()
local sum = 0
for orename, chance in pairs(oretable) do
sum += chance
end
local randomnumber = math.random(sum)
for orename, chance in pairs(oretable) do
if randomnumber <= chance then
return orename
end
randomnumber -= chance
end
end