Hello Developers,
I’m trying to save a string value but I’m not quite sure how to do it, I’ve tried finding tutorials but have failed in doing so, I have worked with datastores before but only with player leaderstats. Any help is very apricated!
You can’t save StringValue
because saving objects it’s not possible, but you can save StringValue.Value
because it’s a string. SetAsync(key, "an example string")
can be used for saving a string. I’m not sure what you meant.
Save the string value you want inside IntValue or StringValue,etc. and script it so whenever the player leave it saves and whenever the player loads in the game back it loads.
So basically, where you would save the leaderstat.Value
is basically the same place where you would save a string. E.g. :SetAsync("EpicKey","Omg I just saved this string")
Saving string values is the same thing as saving an int/number, but you have to input a string in the SetAsync
function instead:
local DataStoreService = game:GetService("DataStoreService")
local MyDataStore = DataStoreService:GetDataStore("InputNameOfDataStoreHere")
MyDataStore:SetAsync(PlayerUserIDHere, "Sample String!")
I hope this helps!
You can do one of the two here:
DataStore:SetAsync(player.UserId, "this is a string")
or
DataStore:UpdateAsync(player.UserId,function()
return "this is a string"
end)
It works the same way as you would save a number value, or anything else.