![]() Roblox’s data stores only allow the certain types to be saved: I will explain these next 2 functions shortly Local gameDataStore = dataStoreService:GetDataStore("Data") You can replace the "Data" in the brackets with anything you'd like. Just underneath where we defined “playerService”, add the code: local dataStoreService = game:GetService("DataStoreService") Next, in our player script, we are going to add a few functions to let us save our data. (You don’t have to name it exactly this, but make sure to called it something along these lines!) Once you have all your values, you should add an intValue called DataId. If you have different values, you can change the code later on to fit your game. Make sure “SpawnPoint” is a Vector3Value and all the others are IntValues. For this example I am going to add “Cash” and “Level” to leaderstats, and I’m going to add “XP” and “SpawnPoint” to playerstats. Now that this player script is done, we can add some values to the folders we just created. PlayerService.PlayerRemoving:Connect(onPlayerRemove) PlayerService.PlayerAdded:Connect(onPlayerAdded) Connect events for when players leave / join May have joined before this script loaded.įor _, player in ipairs(playerService:GetPlayers()) do [[ Here, we want to iterate through all players that This function will run when the script loads Here we want to save the data, we will add this soon This will run when a player leaves the game Local leaderstats = script.leaderstats:Clone() This will run when a player joins the game. Server script (In ServerScriptService): local playerService = game:GetService("Players") It is very important you name “leaderstats” correctly as Roblox looks for this name inside the player when deciding what should go on the leaderboard. Inside this script, add two folders renaming them to “playerstats” and “leaderstats”. Let’s create a server script to give players these stats when they join the game. Playerstats are the stats that we don’t want to show on the leaderboard. ![]() Leaderstats are the stats that show up on the leaderboard when you are in a game: In this tutorial, we will have 2 types of stats: leaderstats and playerstats. ![]() If there are any improvements I could make please let me know, I appreciate you taking the time to read this tutorial! - Shepp2004įirst we need our players to have stats that we can save and load the next time they join the game. I know there are alternatives such as ProfileService and Datastore2, but this tutorial focuses on Roblox’s API, and how to improve the security of your players’ data. This is aimed for people looking to reduce data loss, or those who are new to datastores. In this tutorial I am going to show you how to create a saving system using Roblox’s default DatastoreService.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |