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

How do I make a DataStore that stores BoolValues?

Asked by 4 years ago

Hey, so I'm quite new to DataStores. I'm currently making a quest thingy, where if you don't have a quest completed, you'll recieve the quest by talking to an NPC. The FirstQuest.Value will then be set to true, to indicate the quest has been taken/completed. Now, the problem arises, what if a player leaves and joins back? All their progress, lost. How do I store BoolValues e.g FirstQuest.Value?

All help is appreciated.

1 answer

Log in to vote
1
Answered by 4 years ago

There are some really in depth and great tutorials out there to help get you started on datastores, but here is a simple solution.

local DataStoreService = game:GetService('DataStoreService')
local Players = game:GetService('Players')

local Statistics = DataStoreService:GetDataStore('Statistics')

Players.PlayerAdded:Connect(function(Player)
    local Data = Statistics:GetAsync(Player.UserId) or {Quest1 = false, Quest2 = false}
    Quest1Bool.Value = Data.Quest1
    Quest2Bool.Value = Data.Quest2
end)

Players.PlayerRemoving:Connect(function(Player)
    Statistics:SetAsync(Player.UserId, {Quest1 = Quest1Bool.Value, Quest2 = Quest2Bool.Value})
end)

This is a very basic use of datastores, but it get's the job done.

Ad

Answer this question