Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

is it possible to store data on a model in the game via a local player?

Asked by
InLeXiX 18
3 years ago

Example, a player will want to improve his land when he buys this item, in bool value the value changes to true, is it possible to save this value so that it is there even after shutting down all servers?

2 answers

Log in to vote
1
Answered by 3 years ago

You use DataStore for this. You would also communicate to the server using RemoteEvents or RemoteFunctions since the local player cannot save/load data.

RemoteEvents/RemoteFunctions tutorial here: https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events

Wiki link here for the service: https://developer.roblox.com/en-us/api-reference/class/DataStoreService

Wiki tutorial link here for saving data: https://developer.roblox.com/en-us/articles/Saving-Player-Data

In particular, you would use :GetAsync and :SetAsync/:UpdateAsync for your usage as this fetches and saves data. To get your datastore or make one, define DataStoreService and then use :GetDataStore() on it with desired name as first argument and scope as second argument.

local datastoreservice = game:GetService(“DataStoreService”)
local datastore = datastoreservice:GetDataStore(“Example”) -- scope is by default “Global” I believe

You can then use the Players service (game.Players) and PlayerAdded to track a player joining and PlayerRemoving for leaving players. These are events so you can use :Connect on them to create functions for them for your data save/loading needs.

0
You wouldn't need client to server communication to save or load data, but you would need it to change the data. Subsz 366 — 3y
0
Yes you’re right but I meant that communication because it would cache the data to be saved when the player leaves, not to save/load data ArtFoundation 255 — 3y
Ad
Log in to vote
0
Answered by
Subsz 366 Moderation Voter
3 years ago
Edited 3 years ago

Yes, you use datastores to save values. http://developer.roblox.com/en-us/articles/Data-store Consider reading this article as it explains how to use DataStoreService.

Answer this question