Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Save a bool with datastore?

Asked by
Filipalla 504 Moderation Voter
8 years ago

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

0
and i need the bool in the player Filipalla 504 — 8y

1 answer

Log in to vote
3
Answered by 8 years ago
Edited 8 years ago

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.

0
how did i get the bool in the player? if you are wondering i try to make tools save with datastore Filipalla 504 — 8y
0
So you're trying to save a boolean value to a player? ScriptGuider 5640 — 8y
0
yes Filipalla 504 — 8y
1
Updated the answer ScriptGuider 5640 — 8y
View all comments (5 more)
0
i don't understand Filipalla 504 — 8y
0
how did i check if player had tool? with the bool Filipalla 504 — 8y
0
+ can i get the bool in the player in game.players? Filipalla 504 — 8y
0
You should probably familiarize yourself with the basics of coding a bit more before advancing further in this subject. ScriptGuider 5640 — 8y
0
im good at it but datastores is very hard Filipalla 504 — 8y
Ad

Answer this question