Hello, can someone help me with getting Offline player’s Bool value (with datastore)?
What do you want to achieve?
I want to get the offline players bool value and if its true it will do something. Basicly I want to get a True/False word from the offline player.
What is the issue?
I have no clue how to solve this.
Example:
local DataStore = game:GetService("DataStoreService"):GetDataStore("DataStore")
game.Players.PlayerAdded:Connect(function(Player)
local Leaderstats = Instance.new("Folder")
Leaderstats.Name = "leaderstats"
Leaderstats.Parent = Player
local IsVip = Instance.new("BoolValue")
IsVip.Name = "IsVip"
IsVip.Parent = Leaderstats
local IsVipData
local Success, ErrorMessage = pcall(function()
IsVipData = DataStore:GetAsync(Player.UserId.."-IsVipData")
end)
end)
game.Players.PlayerRemoving:Connect(function(Player)
pcall(function()
DataStore:SetAsync(Player.UserId.."-IsVipData", Player.leaderstats.IsVip.Value)
end)
end)
--------Now tricky part comes:
-- offline player is called "DavidLolHun"
local Name = "DavidLolHun"
if DavidLolHun.leaderstats.IsVip.Value == true then
print("Offline player named DavidLolHun is Vip")
else
print("Offline player named DavidLolHun is NOT Vip")
end
You already have your answer with the code you provided. Take a look at this:
What you’re doing here essentially is whenever a player joins, you’re looking to see if that specfic datastore is true or false. This is exactly what you need to do to get the information, with a few changes.
Because you’re looking for a username, you need to convert that to a userId. This can be done with Players:GetUserIdFromNameAsync. Then, simply feed that value into a function similar to your PlayerAdded. If you’re confused on anything let me know and I’ll try and provide a sample, however that should work fine.
Ye I can get the UserId from it, but the main thing I would ask is when I try your code, it only prints out “nil” and not “false” or “true”. How can I get them printed out?
No the script you made just loads it, to save use SetAsync with the key as the first parameter and the value as the second, SetAsync with the same exact Datastore.