In the previous lesson, we stored a number in the Storage. Storage can store booleans, numbers, vectors, colors, tables and player references. If we want to store the hat that the player owns, we can’t just store the reference to an instance of the object. We must store the MUID of the template, a string that is unique for each template. You can find the template MUID by right-clicking in the Project Content and then pressing Copy MUID. You will get a value with an ID and a name like “DC634DB7D0E457C6:WizardHat”. The id is unique so you will have something different for your project.
Save objects
As the equipment might already be removed for the player when he wants to leave, we will save the fact that the player owns the hat when they buy it.
The function SaveHatInStorage is a function placed inside the ShopServer script that will add a field hat inside the storage of that player. The value is HAT_REF, the MUID of the template. This reference is going to be used to spawn the hat when the player joins the game.
Now that the hat is stored in the storage, we can copy our function SpawnAndEquip from the ShopServer and paste it into the PlayerStorage script. When the players connect, we check at line 12 if the hat field exists. If it exists, we call the SpawnAndEquip with the player and the MUID of the template.
This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
Strictly Necessary Cookies
Strictly Necessary Cookie should be enabled at all times so that we can save your preferences for cookie settings.
If you disable this cookie, we will not be able to save your preferences. This means that every time you visit this website you will need to enable or disable cookies again.
3rd Party Cookies
This website uses Google Analytics to collect anonymous information such as the number of visitors to the site, and the most popular pages.
Keeping this cookie enabled helps us to improve our website.
Please enable Strictly Necessary Cookies first so that we can save your preferences!
There’s an error for the Full ShopServer script on line 10:
What it looks like:
torage.hat = HAT_REF
What it should look like (just missing the small “s” at the beginning of the line):
storage.hat = HAT_REF