Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Save a bool with datastore?

i want the datastore to save a bool how did i do?

1 comment

0

and i need the bool in the player

1 answer

✓ Accepted 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

0

how did i get the bool in the player? if you are wondering i try to make tools save with datastore

0

So you're trying to save a boolean value to a player?

0

yes

1

Updated the answer

0

i don't understand

0

how did i check if player had tool? with the bool

0
  • can i get the bool in the player in game.players?
0

You should probably familiarize yourself with the basics of coding a bit more before advancing further in this subject.

0

im good at it but datastores is very hard

This discussion is preserved as it was. New answers, comments, and votes are closed.