I have a value stored in replicatedstore, how do I save it to database so when I rejoin, the number stays there and doesn't reset??
COMMUNITY QUESTION
How do I store NumberValue to database???
1 answer
Use DataStore Service.
I'll show you a little example of it using a number value(you can change the number value with any number value in the game, it could be a number that is in the leaderstats folder, if you have one).
local saveData = game:GetService('DataStoreService'):GetDataStore('NumberSaver')
local number -- type here the location of the number value.
local plrs = game:GetService('Players')
plrs.PlayerAdded:Connect(function(plr)
local newNumber
local s, e = pcall(function()
newNumber = saveData:GetAsync(plr.UserId) -- gets number from id
end)
if s then
if newNumber == nil then
number.Value = 0 -- put here the number that you want when there is a new player in the game.
else -- if the player already joined the experiece before, it will give the number value the same value that it had before
number.Value = newNumber
end
else
warn(e) -- if there is a error, it will send it to the output
end
end) -- when the player joins the server, the data store will get the number in the user id of that player and put it in number.Value.
plrs.PlayerRemoving:Connect(function(plr)
local s, e = pcall(function()
saveData:SetAsync(plr.UserId, number)
end)
if not s then
warn(e) -- if there is a error, it will send it to the output
end
end) -- when the player leaves the server, the data store will save the number in the user id of that player.
This will change the value of 'number' when player joins and leaves.
This discussion is preserved as it was. New answers, comments, and votes are closed.

5 comments
104: Cannot store Instance in data store. Data stores can only accept valid UTF-8 characters.
thats the error I got
at line 26, add .Value to 'number', I forgot to put that in there.
ive tried that and this is what I got lol ServerScriptService.Database:15: attempt to index number with 'Value'
what did you put in number?