Need Help Choosing A Luck System!

  1. What do you want to achieve? Keep it simple and clear!
  • I would like to create a luck system for opening eggs similar to that of Pet Simulator X. For this, I researched 2 luck systems. I would also like to know the advantages/disadvantages between the two, and how to apply them in an effective manner.
  1. What is the issue? Include screenshots / videos if possible!
  • From what I have researched, there is 2 main types of luck systems. A basic luck system that chooses a number for 0-100 and then goes through a list of items with chances, and if the random chance is less than or equal to the chance of the list chance, it picks that item. The second is called a weighted chance system, which I am still not entirely clear on how it works.
  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
  • I have tried to use the simplest of the two methods, but I was not sure if there was a better way. I also wanted to know how to make a luck boost that increases your chances, but I also do not know the best way to apply this.
local ran = Random.new()
petList = {
	{Name = "Two-Headed Dog", Chance = 40},
	{Name = "Antenna Dog", Chance = 30},
	{Name = "Galaxy Dog", Chance = 4},
	{Name = "Mutant Galaxy Dog", Chance = 0.9},
	{Name = "Mutant Lealah", Chance = 0.1}}
script.Parent.Triggered:Connect(function(plr)
	local chance = ran:NextNumber(0,100)
		
	for i,v in pairs(petList) do
		if chance <= v.Chance then
			print(v.Name)
		end
	end
end)

Sorry if this isn’t the most well-written post, it’s my first DevForum post lol. I would really appreciate if someone took the time to help me through the concept of these luck systems!

Hi so basiclly your “basic” system is accually a less advanced version of a weighted chance system. Let me explain how a weighted chance system works. For example:

1.) Here the sum is = 1000 doesn’t need to be 1000 but it’s ez to calculate at the moment. With Pet1 0.1% chance to hatch, pet2: 1% chance, pet3, 10% and pet4 88,9% chance. Since you’re working with a pet hatch chance it’s recommended to order them from a low chance to a high chance.( Note since we’ll be working with math.random it’s easier to not work with decimals.)

Local Petchances = {
 ["Pet1"] = 1,
 ["Pet2"] = 10,
 ["Pet3"] = 100,
 ["Pet4"] = 889,
}

2.) Then you define the total of your chances by adding every chance to the weight variable.

local Weight = 0
for _, chance in pairs(Petchances) do
 Weight += chance
end

3.) We generate a random number between 1 and our total sum of the chances (The weight).

Local RandomNum = math.random(1, Weight)

4.) Now we reset the Weight variable back to 0 for our next step, you can also use a second variable for this but since we’ll have to reset our Weight variable anyway let’s just use the same variable to make it ourselves easier. After we did that we’re gonna add the chance from our pet list from low to high back on the weight variable and each time we do this we’re gonna check if we reached our random number.

Weight = 0
for petname, chance in pairs(Petchances) do
 Weight += chance
 if Weight >= RandomNum then
  Print(petname)
  Break -- We break it because we reached our goal else it will also give us all the pets that have a higher chance
 end
end
end

I hope that was clear, to answer your next question the Weight chance system almost has no disadvantages over the basic version, because it’s like an “upgraded” version of the basic system. +It’s not hard at all once you know how it works so you might prefer to use this aswell.

To add boosts to your chances of hatching you’ll have to be creative for example if you look at Pet Sim X they have Lucky boost and Ultra Lucky Boost you can create a function that adjust the chance from (1, 50) with a total weight of 1000 times 2 and times 4 with ultra lucky boost. It’s up to you on how you do this. Once the boost ran out you reset the hatch chance back to default.

3 Likes

Thanks! That was pretty clear to me, and now I understand how weighted chance systems work. However, I am still a little confused on the luck boosts, especially the part where you said “that adjust the chance from (1, 50)”. Like mainly, how does increasing the weight increase the luck?

I also make some changes to my current luck system, and in my opinion I don’t see much of a difference between using a weight system or a basic system for it. I could be wrong, but for me this works. If there is any tweaks you think would work, let me know! `local ran = Random.new()
local marketplace = game:GetService(“MarketplaceService”)
petList = {

{Name = "Mutant Lealah", Chance = 0.1},
{Name = "Mutant Galaxy Dog", Chance = 0.9},
{Name = "Galaxy Dog", Chance = 4},
{Name = "Antenna Dog", Chance = 30},
{Name = "Two-Headed Dog", Chance = 100}}

script.Parent.Triggered:Connect(function(plr)
local chance = ran:NextNumber(0,100)
print("No Gamepass Chance: "…chance)
if marketplace:UserOwnsGamePassAsync(plr.UserId,143818986) then
chance /= 1.2
print("Gamepass Chance: "…chance)
end
for i,v in pairs(petList) do
if chance <= v.Chance then
print(v.Name)
end
end
end)`

I don’t know in how far your egg hatching system goes, but with the information you’ve given me your script should work fine.

In terms of the boosts, In a weighted system the higher the weight the more chance you have to hatch a pet right? for example 1/1000 or 50/1000 the chance you hatch the second one is way bigger than the first one. So if you for example make a boost that mutiplies the chances times 2 you would now have 2/1000 and 100/1000 chance to hatch those pets. But you’ll have to limit your range because if you wouldn’t all the chances would multiply by 2 as a result nothing would chance at all. So you can limit the range that only pets with a chance lower than 100/1000 get the multiplier and the rest stays the same.

1 Like

Ah, ok. Thank you so much for helping me through this topic!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.