So, I am trying to create a script that will save, update and load the number of "Special" rocks value ( Number value).
I just can't understand how to save things...
The script is inside NumberValue.
This is what I've created so far and I know that it's a total fail. -_-
Please take some time to help me.
-- Saves and updates the value local Datastore = game:GetService("DataStoreService"):GetDataStore("SpecialRockValue") game.Players.PlayerAdded:Connect(function(player) local Value = script.Parent pcall(function() local specialrocks = Datastore:GetAsync(player.UserId, Value) end) local Save = Datastore:SetASync(player.UserId, Value) if Save then Save.Value = Value.Value end end)
EDIT: I just want to say that I've also read every catalog about Datastore on ROBLOX Wiki but still no help.
I commented on most lines that have importance in the script, if you have any questions let me know. What this does is loads the saved data if they have it, or saves it when they leave.
local DS = game:GetService('DataStoreService'):GetDataStore('SpecialRockValue') game:GetService('Players').PlayerAdded:Connect(function(plr) local SpecialRocks = Instance.new('IntValue') SpecialRocks.Parent = plr SpecialRocks.Name = 'SpecialRocks' local key = 'id-'..plr.UserId -- get the UserId for the key (better than username as people can change their name) local getSavedData pcall(function() -- Use pcall in case the retrieval fails getSavedData = DS:GetAsync(key) -- get saved data using the key(if there is any) end) if getSavedData then -- if there is saved data then SpecialRocks.Value = getSavedData[1] -- load saved data else local ValuesToSave = {SpecialRocks.Value} -- table for values you want to save DS:SetAsync(key,ValuesToSave) -- save all the values in the table end end) game:GetService('Players').PlayerRemoving:Connect(function(plr) local key = 'id-'..plr.UserId -- get the userId for the key local ValuesToSave = {plr.SpecialRocks.Value} -- table for values you want to save DS:SetAsync(key,ValuesToSave) -- save all values in table end)
http://www.mediafire.com/file/rpb4jxaaw6udk89/2018-08-30_14-48-02.flv/file
I made a video of my experience of your script, It worked fine for me. You can go check my methods in the video.