I’m trying to figure how I would implement a luck boost into a pet hatching system.
When a player activates this luck boost (through a potion system), I’d like their luck for more rarer pets to be doubled.
I’m just lost how I’d do it though.
local function choosePet(egg)
local Chance = math.random(1,100)
local Counter = 0
for _,pet in pairs(game.ReplicatedStorage.Pets[egg.Name]:GetChildren()) do
Counter = Counter + pet.Rarity.Value
if Chance >= Counter then
return pet.Name
end
end
end
Using your current framework, define your rarities between certain intervals (if Chance >= 1 and Chance <= 3 then print(“Legendary!”)).
Now with your rarities let us establish some things that you may find useful:
A datastore that has an entry if a player luck boost is active and how much time is remaining
This establishes which players have the potion and which players do not. We can now make two systems, one which is for the player without the boost (the one you currently have) and now if the Player’s data has the potion boost active, we give them a different system.
Establish the different system
We can use the same frame, just make sure the script accesses the data store of the player, and if the player has the item active (we can use a Boolean to check) then apply a modified system which doubles the chances (this means legendary rarity is 1<= chance <= 6 instead of 1<= chance <= 3 (this is up to you)).
I apologize in advance as reading over it I only outlined a general framework and not specific examples, but I hope this helps!