Pet hatching system

hello,
i am trying figure out how to make pet hatching system preety long time same as another simulators games with multi and all, sombody know how they making the pets actually collectable from eggs random and they actually added and saved in players inventory?.
example of games with that:
jatpack simulator: 🚀 Jetpack Simulator! ⚡ - Roblox
Bee Swarm simulator: Bee Swarm Simulator - Roblox
Pet simulator 2: Pet Simulator 2! - Roblox
Mining simulator: Mining Simulator - Roblox
thanks,
REALINONOOBYT.

2 Likes

Well, I can answer the saving part: they all use DataStore to save the data for the eggs and pets. Also, define “random”. Random from drops, quests, daily logins? I’m not sure what you mean, but it’s more than likely incorporating Random.

1 Like

i am mean that gives random pet to the player.

You can easily achieve that by using the Random class (or math.random) on the length of a folder where all the pets are located in and using that value as the index. Like so:

local Pets = PetsFolder:GetChildren()
local RandomPet = Pets[math.random(#Pets)]

Of course, you’d replace “PetFolder” with where your pets are actually stored, since that was just an example.

1 Like

Uh, I think he meant with chances.

What I do in my game Timber is send a remote event to the server. The server and client share a database [module script] of pets in Replicated Storage. The server chooses one of the pets inside of this database at random [based on the probabilities you’ve set up]. It then sends the client the id of the pet that it chose. Upon receiving this id, the client can look up the pet in the shared database and display the “hatched” pet. Of course, actually adding the pet to an inventory system and displaying the animation is something else entirely.

I believe adding the pet to the Datastore is server sided? Else I’m certain it will be abused.

Yes, always load / save data on the server

1 Like