i want the datastore to save a bool how did i do?
Save a bool with datastore?
1 answer
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.
Edit
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.
9 comments
how did i get the bool in the player? if you are wondering i try to make tools save with datastore
So you're trying to save a boolean value to a player?
yes
Updated the answer
i don't understand
how did i check if player had tool? with the bool
- can i get the bool in the player in game.players?
You should probably familiarize yourself with the basics of coding a bit more before advancing further in this subject.
im good at it but datastores is very hard
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
and i need the bool in the player