Currently, I am trying to make a script for a global banned list. I am trying to add playerIds to a table and possibly retrieve these playerIds. So far I got the part down where I can match playerIds (raw data for them though) and the part where they get kicked. Other than that I need help. Can anyone lead me in the right direction (new to using DataStores and I don't understand the wiki well)?
referencing or creating new data store name
local DataStore = game:GetService('DataStoreService'):GetDataStore('Name'); local Players = game:GetService('Players')
function to authenticate player
ban status
if true, banned, elseif false, not? :D
function RequestBanStatus(player) return DataStore:GetAsync(player.userId) end
function to update playerId
's data store
depending on boolean
argument
local SetBanState = function(playerId, boolean) DataStore:UpdateAsync(playerId ,function(state) if boolean == false then return false else return true end end) end
calls RequestBanStatus
function and
kicks player
if returned value true
Players.PlayerAdded:connect(function(player) if RequestBanStatus(player) then pcall(function() print(player,'banned') end) end end)
You could also create a BindableEvent and connect it to the
SetBanState
function so that you can call it in your chat based administration scripts. You can also create a table within the script containing permanently banned userIds which you would of course add in theRequestBanStatus
function in addition to the already existing check.
local DataStore = game:GetService('DataStoreService'):GetDataStore('Name'); local Players = game:GetService('Players') local SetBanState = function(playerId, boolean) DataStore:UpdateAsync(playerId ,function(state) return boolean or state end) end function RequestBanStatus(player) return DataStore:GetAsync(player.userId) end Players.PlayerAdded:connect(function(player) if RequestBanStatus(player) then pcall(function() warn('player, banned') end) end end)