I am making a blacklist system where the script fetches your data from a datastore and see if Blacklisted is true or not. But how would I insert such into a datastore because new players will not have them while people who already joined will have Blacklisted set to false unless they are blacklisted.
What way could I check if theres an already existing Blacklisted value under their UserId and if not how would I insert it?
Datastores don’t save data to the players. It saves to a string value which could be anything; This means they don’t have to be in the game to become blacklisted.
Without the player joining the game you can use a admin menu or something of the sorts to add them to the blacklist.
This means that when they join the game it will fetch the value you or your script assigned to the datastore associated with the player.
local DSS = game:GetService("DataStoreService")
local BlackList = DSS:GetDataStore("BlackList")
--- Blacklisting a player
function BlackList(Identifier,Reason)
BlackList:SetAsync(tostring(Identifier),tostring(Reason))
end
--- Checking for blacklist
game.Players.PlayerAdded:Connect(function(Player)
local BlackListCheck = {BlackList:GetAsync(Player.Name),BlackList:GetAsync(Player.UserID)
if BlackListCheck[1] == nil and BlackListCheck[2] == nil then
--- Not BlackListed
else
if BlackListCheck[1] then
Player:kick("You Have Been BlackListed From This Game Reason" .. BlackListCheck[1])
end
if BlackListCheck[2] then
Player:kick("You Have Been BlackListed From This Game Reason" .. BlackListCheck[2])
end
end
end)
Yes I am going to use some other script that manually sets blacklisted to true to them but I’m just looking how to fetch this value when they join the game
If you want a better explanation of how to make the most of stores I do have a few posts out there explaining in more depth that cover to the point where you can pull datastores from other datastores and make an infinite store. Mines at the point where I can save parts and have a backlog of information all the way to when they first joined.