I am trying to make a data store which saves Bool Values, but I’m unsure how to. The way the system works is, a BoolValue is created, and inserted into a “Values” folder, by a local script once the player clicks a purchase button. This value is set to false, but when moved to the folder it’s set to true.
Does anyone know how to save the values which have been inserted, and how to make sure it saves their values?
DataStoreService documentation: here
Uhh script I guess?
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("PlayerData")
game:GetService("Players").PlayerAdded:Connect(function(plr)
local Data = DataStore:GetAsync(plr.UserId)
local Folder = Instance.new("Folder",plr)
Folder.Name = "Values"
local b = Instance.new("BoolValue",Folder)
b.Name = "Bool"
if Data then
print(Data)
end
end)
game:GetService("Players").PlayerRemoving:Connect(function(plr)
DataStore:SetAsync(plr.UserId,plr:WaitForChild("Values"):WaitForChild("Bool",math.huge).Value)
end)
Yes but OP specified that the value is added through a local script, which means in order to save it they’ll need to call SetAsync() from the server, which they can request with a remote event.
Yes. It’s used in a “Buy Item” system where the player buys an Item by clicking the button, and the button has a script in it where it creates the bool value, sets the value to false, and it has a designated name for the value. Then, the value is put inside the “Values” folder where it’s then changed to true and then the folder saves the value.