In other words, when I leave the bool value will save and when I rejoin it load. Please do the script in the easiest way possible.
✓ ANSWER ACCEPTED
How can I make data store save a bool value?
1 answer
✓ Accepted answer
You can just use GetAsync() and SetAsync()?? Lua already implements them within DataStore
Wiki Article: https://developer.roblox.com/en-us/articles/Saving-Player-Data
Youtube Tutorial: https://www.youtube.com/watch?v=n1UpT2csAzo
I cannot give a full script because that would be spoonfeeding, but I can give a sample
-- when a player joins
local data
local success, errormessage = pcall(function() -- pcall is great to use for loading data
data = DataStore:GetAsync(playerUserId) -- however you want to assign data (by id, by name, etc etc)
end)
if success then -- if you could get the data
if data then -- if there is actual data
yourValue = data.yourValue -- replace yourValue with...the name of your boolvalue
end
end
and then when a player leaves, setting async
local data = {
yourValue = player.leaderstats.yourValue.Value -- where do you put the boolvalue? in leaderstats, in the actual player, etc etc?
}
local success, errormessage = pcall(function()
DataStore:SetAsync(playerUserId, data) -- sets async, saving data, you replace playerUserId with how you want to store it for each player
end)
if success then -- if the data saves, if success
print("data saved successfully") -- woohoo it saved
else
print("something went wrong with saving data")
warn(errormessage) -- tells you what happened in a warning format
end
Pcalls() and other lua globals: https://developer.roblox.com/en-us/api-reference/lua-docs/Lua-Globals
Hope this helps and if not then i hope it leads you in the right direction
This discussion is preserved as it was. New answers, comments, and votes are closed.
