i want the datastore to save a bool how did i do?
Passing the boolean as the second argument to SetAsync (or returned through the UpdateAsync callback, if that's what you're using) will work just fine. Here's an example:
SetAsync
Example:
Datastore:SetAsync("Key", true)
UpdateAsync
Example:
Datastore:UpdateAsync("Key", function() return true end)
Just make sure Datastore
is the actual data store you created - not the DataStoreService.
Based on your feedback, I see you want to save a value to a specific player. When saving data to players, it's very important you use their UserId
as some form of keeping track of what data belongs to them. That UserId
will then be set as the key (variable) of the data you saved. Here's an example of something that will save a true value to each player that joins the server:
local Datastore = game:GetService("DataStoreService") local Players = game:GetService("Players") -- A new data store called 'PlayerData' local PlayerData = DataStore:GetDataStore("PlayerData") Players.PlayerAdded:connect(function(Player) local Old = PlayerData:GetAsync(Player.UserId) if Old == nil then print("Player has not been here before") PlayerData:SetAsync(Player.UserId, true) else print("Player has been here before") end end)
The code above will act as a way to identify when someone who's never joined your game before, joins. This is just an example, the method to save player data in general remains the same.