[Data Saving] How to make A Pet Simulator X Game on Roblox - Part 6 — Transcript
Full transcript
- 0:00hello everyone and welcome back to a new
- 0:02video on the how to make a bit Simulator
- 0:04Xbox game series in this video I'm going
- 0:07to be showing you how to save the areas
- 0:09that we bought and the player stats and
- 0:12the players coins and gems
- 0:14also if you guys want to support me and
- 0:17want to have access to all of the
- 0:18project files including the one you're
- 0:20watching right now they will all be
- 0:21available on my patreon in Nintendo all
- 0:24tier
- 0:24so when recording this video I realized
- 0:27that I did not show the INF the
- 0:28interface of creating attributes
- 0:31so here's how attributes work when you
- 0:33create so here's my instance I have a
- 0:36part selected if I scroll down and click
- 0:39add attribute it will say tell me to
- 0:41give my attribute name so for example
- 0:44test
- 0:45and it will give me it will tell me to
- 0:48select the type so string or Boolean I'm
- 0:52just going to say Boolean and if I press
- 0:54save your attribute should pop up here
- 0:56okay so the first thing I'm gonna do is
- 1:00go to server script service and I'm
- 1:02going to create a new script and I'm
- 1:03going to call it data save
- 1:06now I'm going to
- 1:09remove the print hello world I'm going
- 1:12to get some services so local players is
- 1:15equal to game come on get service
- 1:16players
- 1:19and then we need data source service
- 1:21silicon data store
- 1:24service is equal to game come on get
- 1:27service data source service and then I'm
- 1:30going to create a reference to server
- 1:33storage so local server or maybe
- 1:35actually we don't really need that
- 1:37I think I'm just going to create a data
- 1:41source local data store is equal to
- 1:44data store service go and get data store
- 1:48and I'm just going to give it a key so
- 1:51create the random key for me I'm just
- 1:53going to say
- 1:55um
- 1:56my data store Key
- 2:00and in here we are going to get the
- 2:02player data so we'll call player data is
- 2:05equal to
- 2:06and I think we have the folder inside of
- 2:10the main server script but I think what
- 2:12I'm going to do is just drag it inside
- 2:14of the data saver and that should work
- 2:17so local player data is equal to script
- 2:20dot player data
- 2:22and what I'm going to do to prevent this
- 2:24from erroring is I'm going to enter the
- 2:27main server script and in here I'm going
- 2:31to just comment this out or maybe just
- 2:33delete it
- 2:35but I think I'm just going to comment it
- 2:38so
- 2:40toggle comment
- 2:42and I'm going to go back to my data
- 2:44saver so
- 2:46blurry data and I'm going to create a
- 2:48function for save data so we'll call
- 2:50function save data
- 2:52and that's of course going to take the
- 2:53player as the first argument and another
- 2:56function for load data so local
- 2:59function and I think I'm going to call
- 3:01it load data so load data and that's
- 3:05also going to take the player
- 3:07and then I'm going to have a function
- 3:11layer removing so layer
- 3:14removing
- 3:17and that's also going to take the player
- 3:20and then I'm going to
- 3:23create the events so players.player
- 3:26added come on connect function load data
- 3:29so whenever a new player is added we're
- 3:31going to call the load data function and
- 3:33whenever a new player left so whenever
- 3:38layer removing so whenever a player
- 3:40leaves the game come on connect we're
- 3:42gonna call the player removing function
- 3:46okay so after calling those two
- 3:49functions sometimes when you are the
- 3:52last player in the server and you leave
- 3:55the game the server might shut down
- 3:57before you your data gets saved so what
- 4:01I'm gonna do is game common bind to
- 4:03close function
- 4:08and what I'm gonna do is Loop through
- 4:10every single player in the game so for
- 4:11underscore comma player in pairs uh
- 4:15players
- 4:16go and get going gets players
- 4:19I'm going against players
- 4:21dude
- 4:23I think I added an extra parenthesis
- 4:26now this gets cold whenever you shut
- 4:29down little servers or just something
- 4:30like that happens
- 4:32then we're gonna call that function and
- 4:34quarantine don't wrap
- 4:37uh save data
- 4:40player
- 4:43and after doing that what I'm gonna do
- 4:45is inside of the player moving function
- 4:48I'm going to call the save data function
- 4:51so save data player so whenever a player
- 4:53leaves the game we are calling the
- 4:56play removing function and we are going
- 4:58to call the save data function
- 5:02now after doing that what I'm going to
- 5:04do is
- 5:06go back to my saved data function and in
- 5:10here I'm going to create a table so a
- 5:12table called the data
- 5:14and inside of that data table
- 5:16it actually it's going to be empty and
- 5:19I'm going to Loop through every single
- 5:20folder in the player so for underscore
- 5:23comma folder in pairs player go and get
- 5:27children
- 5:30do
- 5:31and what I'm gonna do is check if player
- 5:35data
- 5:37go and finds first child
- 5:39folder.name
- 5:42then so what what we're doing here is
- 5:45basically just checking if the
- 5:48blur data folder has a has a this folder
- 5:52inside of it so if it does then what
- 5:54we're going to do is
- 5:56check
- 5:58if player data if the folder from the
- 6:01player data
- 6:03has this attribute called save children
- 6:06and is equal equal to true so
- 6:10what I'm going to do is okay I'm gonna
- 6:13explain what this does so
- 6:15if any of these folders have this
- 6:18attribute called save children
- 6:21if it's true then we are going to save
- 6:23everything that's inside of that folder
- 6:26if it is false then we're not going to
- 6:27do that so for example for our pets
- 6:30folder I'm going to add an attribute and
- 6:32it's going to be a Boolean and I'm going
- 6:34to call it save children
- 6:38now I do want
- 6:41the children from the past folder to be
- 6:43saved so all of our pets will be saved
- 6:45so I'm gonna do that and then after
- 6:49doing that I'm going to go back to the
- 6:50script
- 6:52and what I'm gonna do
- 6:54is
- 6:56so data
- 6:58folder.name
- 7:01is equal to an empty table so we are
- 7:03creating another table inside of that
- 7:04table
- 7:06and what I'm gonna do is check
- 7:10if blur data folder.name calling
- 7:14attributes save children values so
- 7:18if that folder
- 7:20if you want to save the values of the
- 7:22children inside of a certain folder for
- 7:24example our leader stats so we want we
- 7:28want it to save the coins and gems but
- 7:30we also wanted to save the children
- 7:32values so what I'm going to do is just
- 7:35go to my leader stats and I'm going to
- 7:37add an attribute and it's going to be
- 7:41a
- 7:42Boolean again and save children values
- 7:49now I'm going to make sure that this is
- 7:51checked
- 7:52because we do want to save our coins and
- 7:54gems and let's say you have a currency
- 7:56that you don't want to save actually
- 7:58we're going to get to that later
- 8:00so now what I'm going to do is for
- 8:03underscore commit child
- 8:05in pairs
- 8:07folder call and get children
- 8:11do
- 8:12so we are looping through all the
- 8:14children inside of that folder that I'm
- 8:17gonna check if not
- 8:20a child can get attribute
- 8:25do not do not save value then
- 8:31so maybe you won't
- 8:33some values to save but some values do
- 8:36not save so for example I want my
- 8:41sensitive values value to not save then
- 8:43I'm going to add a
- 8:45string value
- 8:47and I'm going a string attribute and I'm
- 8:50going to call it do not save value
- 8:53however we don't the uh
- 8:57this is only going to work if the values
- 9:01folder
- 9:02has the Boolean called save children
- 9:07and it's set to true so
- 9:09we're going to save all the children
- 9:11inside of the folder so if this happens
- 9:13we are going to save all the children in
- 9:16the folder
- 9:17but We're Not Gonna Save the value of
- 9:20this sent to value
- 9:22because it has this attribute called do
- 9:24not save value
- 9:26and
- 9:27this is also only going to work if we
- 9:30also have these save
- 9:33children values
- 9:37and it's going to be a Boolean again so
- 9:39if we want to save the children values
- 9:40we're going to do that and we also go
- 9:42and we are also going to save the
- 9:45children
- 9:46but we're not going to save the
- 9:49value of the sent to Value so I'm going
- 9:52to get rid of this I want this both of
- 9:54these to be false and I'm also going to
- 9:56remove this attribute
- 9:58now what I'm going to do is table don't
- 10:01insert so table dot insert and data
- 10:07square brackets folder.name
- 10:10oh no
- 10:12a table child dot name
- 10:16child.name comma child dot value
- 10:21comma child dot class name
- 10:26okay so we are saving we are adding a
- 10:33a table inside of the
- 10:36table that we just added so this table
- 10:38right here we are adding another table
- 10:40inside of it and that table will contain
- 10:43uh the properties of the child so the
- 10:47child name the child value
- 10:50and the child class name now I'll we're
- 10:54gonna see why this is useful why why
- 10:56we're gonna use the class name later
- 10:58so what I'm going to do after that in
- 11:01here I'm just going to
- 11:05put an else right here
- 11:07so if we
- 11:10don't have the safe children values
- 11:15then what I'm gonna do is
- 11:18we're gonna do that again so for
- 11:20underscore come a child in pairs let's
- 11:23go and get children do
- 11:27and what we're going to do is again
- 11:28check if it doesn't have the do not save
- 11:31value string
- 11:35or attributes and what we're gonna do
- 11:37this time is just
- 11:39Tableau insert data square brackets
- 11:42folder.name and child.name and
- 11:45child.class name so we are not saving
- 11:47the value so if we we are saving the
- 11:50children values then we are going to add
- 11:52the value of the child to the table if
- 11:55we are not doing that then well we're
- 11:58not going to save the child value we're
- 11:59only saving the child name and the child
- 12:03class name this is getting kind of
- 12:04confusing for me to explain and I'm
- 12:07really bad at explaining so sorry about
- 12:09that
- 12:10now what I'm going to do is after this
- 12:13big for Loop right here
- 12:15I'm going to go down and local success
- 12:19comma error MSG so error message is
- 12:22equal to P call function
- 12:25and data store
- 12:27so the data server that we created right
- 12:29here going save async so we are saving
- 12:33the data
- 12:34con save set async sorry
- 12:37uh player don't user ID
- 12:41comma actually sorry about user ID dot
- 12:44dot
- 12:45B
- 12:46now if you want a key for this
- 12:50I want to add it it's optional but I do
- 12:53want to have a key
- 12:55and we are going to save the data table
- 12:57so
- 12:59they don't
- 13:01now what I'm gonna do is check if
- 13:03success then
- 13:06and we're gonna print
- 13:08uh saved data
- 13:12else
- 13:15we are going to warn
- 13:17the ER MSG now what this is doing is
- 13:22basically
- 13:23if saving the data was a success then we
- 13:26are going to well print save data if
- 13:29it's not then it's not going to error
- 13:31this and break the whole script it's
- 13:33just going to warn us that it didn't
- 13:35work and it's going to tell us what we
- 13:36did wrong
- 13:38now what I'm going to do is go back I'm
- 13:40going to go to the load data function
- 13:43and what I'm going to do is Loop through
- 13:46so for underscore comma V in pairs
- 13:50layer data call and get children
- 13:53to do and we are going to take every
- 13:56single folder and value inside of the
- 13:58player data and
- 14:00clone it and parent it to the player so
- 14:03the colon clone the parent is equal to
- 14:06player so we are cloning it then
- 14:08parenting it to deep player
- 14:10after that local data
- 14:13this is just going to be in a uh this is
- 14:16going to be set to nil
- 14:18so again local success comma error MSG
- 14:24is equal to pical function
- 14:27and data is equal to and data store
- 14:31can get async this time not set async
- 14:34get a sync player.user ID
- 14:38dot dot key
- 14:40comma actually we don't need the comma
- 14:43so what what we are doing in here is
- 14:46setting a sync and then here we're going
- 14:48to get the data that we saved so as you
- 14:50can see in here we save the data and the
- 14:53key that we gave it is the
- 14:54player.userid.key
- 14:57and in here we have an empty variable
- 14:59called Data it's set to nil and
- 15:02here we are setting that data to the
- 15:06data that we saved earlier
- 15:08now again we are doing the the P call
- 15:10for the same
- 15:12reason so that it does not error and
- 15:15break the entire script now what I'm
- 15:16going to do is check if error MSG then
- 15:20so if it errors then we are going to
- 15:23kick the player so player come on kick
- 15:26and we are just going to say uh couldn't
- 15:31save data
- 15:36couldn't save that I will just okay
- 15:38could not
- 15:39save data
- 15:41now the reason why we are kicking the
- 15:43player is so that for example the player
- 15:45is going to so the player already played
- 15:48the game and grinded and got a thousand
- 15:50coins
- 15:52so if he leaves the game and rejoins and
- 15:55those thousand coins weren't able to
- 15:58load if he plays the game and leaves
- 16:02again
- 16:03it's going to save zero coins so if we
- 16:06could not load the data then we are just
- 16:08going to kick the player
- 16:10but before we do that I'm also going to
- 16:12warn the error message
- 16:15okay so after that I'm gonna check if
- 16:18the data
- 16:20is equal to something so if data then
- 16:23and I'm going to live through the data
- 16:25do
- 16:27and I'm going to check if hashtag V
- 16:32is greater than zero
- 16:34then
- 16:35what we're going to do is for X comma C
- 16:40now I'll explain what this does later in
- 16:42pairs
- 16:44V
- 16:45do
- 16:47and what we're going to do is check if
- 16:50player
- 16:51do strings I can't find first child C
- 16:55square brackets one
- 16:58now this is going to be hard for me to
- 17:00explain so I'm just going to do that
- 17:02later
- 17:04so if if that then we're gonna do this
- 17:09else we are going to create a new value
- 17:13so local value
- 17:16is equal to
- 17:17instance.new and it's going to be to
- 17:21string
- 17:22uh C square brackets three
- 17:25by the way this is the class name that
- 17:27we just saved
- 17:28and value dot name is equal to
- 17:33C square brackets one
- 17:35and value dot value is equal to C square
- 17:41brackets two
- 17:43and value dot parent
- 17:46is equal to player
- 17:49square brackets to string I
- 17:52okay so now it's time for me to explain
- 17:54what this does
- 17:56now
- 17:58if V is greater than zero this is
- 18:00basically the folder inside of the data
- 18:02because if you remember inside of each
- 18:04inside of the data table
- 18:07we created a folder
- 18:09a table for the folder that we saved and
- 18:13basically V in here means the folder
- 18:16that we saved so we gotta check in if
- 18:19how how much stuff is in the folder is
- 18:22greater than zero so if it's so if there
- 18:25is nothing in the folder then we're not
- 18:26gonna do anything we're not going to do
- 18:28all of this but if there is then
- 18:31we are doing from X for X comma C now X
- 18:35is the index
- 18:37I renamed it to X because I is already
- 18:40used here
- 18:42and C
- 18:44is basically
- 18:47the okay so C
- 18:50is this
- 18:53it's this table that we saved in here
- 18:56I don't know if this makes sense but so
- 18:58seize the value that we saved
- 19:01so C1
- 19:03is
- 19:05the values name so child.name
- 19:08and C2
- 19:11is the child's value so child.value
- 19:16and in here
- 19:18when we are creating the value C3 is of
- 19:24course the class name
- 19:25and C1 is the name and C2 is the value
- 19:29and to string I is basically
- 19:34the name of the folder okay so now I'm
- 19:37going to test this out and see if it
- 19:39works
- 19:40so what I'm gonna do is
- 19:44so we want to save the pets
- 19:47and the leader stats values
- 19:51I'm also going to have the save children
- 19:56dual value so save children Boolean
- 20:00true
- 20:03okay so now I'm going to see if this
- 20:05works
- 20:07so before testing this out into On
- 20:09Studio we're gonna go to game settings
- 20:11and security
- 20:14and enable Studio access to API services
- 20:18now if you play the game
- 20:21that should hopefully work
- 20:24so we have 1500 coins and a thousand
- 20:27gems I'm going to get a pet
- 20:32so I'm just going to Hash this pet
- 20:37and I'm going to change my coins and
- 20:41gems value
- 20:43so coins will be maybe
- 20:471123 and for the gems I'll have it set
- 20:50to 542.
- 20:55so remember these two values now I'm
- 20:57going to leave the game
- 20:58and see if this works
- 21:01so sprinted saves the data now we are
- 21:04going to see if it will load the data
- 21:09Okay so
- 21:10it couldn't load the data so we are
- 21:13going to check why this is happening
- 21:16okay so I found the fix all I did is
- 21:20check if C square brackets 3 is equal
- 21:23equal to nil then value is equal to
- 21:25instance dot Nu to string C2
- 21:28else the value is equal to instance dot
- 21:31Nu two strings C3 now the reason why is
- 21:35because if we don't have these save
- 21:37children values attributes set to true
- 21:40then C3 is not a thing because there is
- 21:43nothing in the third index
- 21:47so I basically just checked
- 21:50if C3 is equal equal to new then C2 if
- 21:54not then C3
- 21:56so this I think works so if I join the
- 22:00game
- 22:01I should have a cat saved
- 22:05and if I just go ahead and modify my
- 22:08coins and gems values so liter sounds
- 22:10coins and gems coins 323
- 22:14coins uh okay so coins
- 22:18for 400
- 22:21and 64.
- 22:26and then I'm going to stop the game
- 22:30and play it again
- 22:32and it should save everything so as you
- 22:35can see I have 464 coins and 323 gems
- 22:39okay so I just found a bug with the
- 22:42system so if you have you hatched for
- 22:45example two cats it will only load one
- 22:48cat and the reason why is because in
- 22:50here we are checking if the value is
- 22:52already there then we are just updating
- 22:54its value so what I'm going to do is
- 22:56just get rid of these three lines of
- 22:58codes right here and get rid of the end
- 23:01in here and I'm going to go to format
- 23:03format document and now everything
- 23:05should work just fine so I'm going to
- 23:07play the game
- 23:12and I'm just going to hatch two cards so
- 23:16here's the first one
- 23:18I'm gonna wait for this animation to
- 23:20play and I'm gonna hatch the second one
- 23:23okay so now I have two cats and a
- 23:26thousand four hundred four hundred and
- 23:27eighty coins and I'm going to leave and
- 23:30rejoin
- 23:35and now we have a thousand for 480 coins
- 23:38and we also have two cats
- 23:41now what I'm going to do is show you how
- 23:43to load the cats into your inventory
- 23:48so just enter the x-client local script
- 23:52so just go to star player scripts and
- 23:54enter X client and I'm just going to
- 23:58Loop through so for underscore some of
- 24:00the in pairs player top Pets Come and
- 24:04Get children
- 24:06do and create template the dot name
- 24:12and I'm also just going to
- 24:16wrap this in accordance so quarantine
- 24:2314 dot wrap
- 24:26and it's just going to take the function
- 24:29so create templates comma V Dot name
- 24:34okay so just do this and also make sure
- 24:36to add a weight in here so it has to
- 24:38wait five seconds and if you play the
- 24:40game now
- 24:41we should have two cats and two cats
- 24:45loaded onto our inventory so if I wait a
- 24:47bit
- 24:48they should load and now we can equip
- 24:50them oh we can't equip them
- 24:53okay that's a problem we're gonna have
- 24:55to fix
- 24:57okay so it says attempt to index nil
- 25:01with concleral children so
- 25:05I'm gonna go ahead and try to fix that
- 25:07okay so I just found out why and it was
- 25:10very simple just
- 25:13copy this
- 25:16copy these lines of codes of codes right
- 25:18here that we commented and go back to
- 25:21our data save script and just
- 25:24face them here
- 25:26and remove the
- 25:28comment so this local folder is equal to
- 25:32that and Dot parents is equal to
- 25:33workspace dot main folder
- 25:35unscoreworkspace.playerpets
- 25:37and that should work now if I play the
- 25:40game I should
- 25:41be able to equip my pets
- 25:46I'm just going to open up the pets
- 25:48inventory and I'm going to equip a path
- 25:50and as you can see it works and both of
- 25:52them should work
- 25:54okay so they both work
- 25:56now what I'm going to do is show you how
- 25:58to save the areas so if I go to my areas
- 26:00I added a an attribute safe children and
- 26:04Etc true
- 26:05but if you play the game
- 26:11there is itself says purchase
- 26:16and we still have to buy it
- 26:20so I'm gonna show you okay so uh
- 26:24it did save it now I'm going to leave
- 26:26the game
- 26:27rejoin
- 26:33and we do have the area that we just
- 26:36bought but if I go here
- 26:38then nothing happens so it says interact
- 26:42so what I'm gonna do is
- 26:47in the main server script we're gonna go
- 26:49down and whenever we
- 26:51want to purchase a door instead of doing
- 26:53this all we have to do
- 26:55is check if player so
- 27:00we need a way to get the player so what
- 27:03I'm going to do is just go back here and
- 27:07create a blur added event in here
- 27:14and I'm just going to delete this
- 27:17and what I'm gonna do
- 27:20is just check
- 27:23if player okay
- 27:28I'm going to Loop through every single
- 27:30door
- 27:33and what I'm gonna do is check if layer
- 27:37on the areas no areas gonna find first
- 27:42child
- 27:44door.name I'm gonna go back and see if
- 27:48okay so area one that should work
- 27:51door.name then
- 27:53I'm just going to fire a remote event so
- 27:57remotes
- 27:58we should have a purchase door
- 28:03remote function
- 28:06so
- 28:08I'm gonna see how this works so in here
- 28:11when we purchase the door
- 28:13where is it
- 28:15Bridges doorcon fire client okay all I'm
- 28:18gonna do is I'm going to
- 28:20add the remote event and I'm going to
- 28:22call it destroy door
- 28:24or remove
- 28:26door so
- 28:28remotes
- 28:31replica okay replicator storage
- 28:35where is it
- 28:38replicated storage so again the
- 28:41replicated storage spot remotes
- 28:43dot remove door calling fire client and
- 28:46it's going to take the player
- 28:48and what I'm going to do is go back to
- 28:50my main client script and right here
- 28:53where it says
- 28:54okay so I'm gonna go here I'm gonna do
- 28:56remotes Dot
- 29:00purchase door or don't remove the door
- 29:04the online event called connect function
- 29:08and I'm just going to do
- 29:11take the door
- 29:13door on Destroy
- 29:16now I'm going to go back to my main
- 29:18server and I forgot to send the door
- 29:20itself
- 29:21okay so now this should work
- 29:24if you play the game and you own a door
- 29:25it should destroy itself
- 29:31oh I forgot to do something
- 29:34we have to wait a couple of seconds
- 29:36before doing that
- 29:44maybe five seconds
- 29:49so if I join the game
- 29:50after a couple of seconds
- 29:53the door gets destroyed and I can go
- 29:55through it without having to buy the
- 29:57door again
- 29:58okay so I think this is going to be it
- 30:00for today's tutorial if this helped make
- 30:02sure to subscribe like the video share
- 30:04it with your friends and I'll see you
- 30:05all in the next video bye
About this transcript
This page contains the full transcript of [Data Saving] How to make A Pet Simulator X Game on Roblox - Part 6 by polarisprog, generated from the public captions YouTube serves with the video. The transcript has 4,035 words across 660 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.