Datastores are not limited to just players. In fact, you can make the key of a datastore any string you want. However in this case, I would make a data store wherein the keys are player ids (don't use player names!) and the values are bools indicating whether or not the player is banned.
local DataStoreService = game:GetService("DataStoreService")
local BannedPlayersStore = DataStoreService:GetDataStore("GameData")
function banPlayer (id)
local success , errorMsg = pcall(function()
BannedPlayersStore:SetAsync(tostring(id) , true)
end)
if not success then
warn("Failed on SetAsync(.."id.." , true) to BannedPlayersStore")
warn(errorMsg)
end
end
function removeBanFromPlayer (id)
local success , errorMsg = pcall(function()
BannedPlayersStore:SetAsync(tostring(id) , false)
end)
if not success then
warn("Failed on SetAsync(.."id.." , false) to BannedPlayersStore")
warn(errorMsg)
end
end
function isBanned (id)
local success , banned = pcall(function()
return BannedPlayersStore:GetAsync(tostring(id))
end)
if not success then
warn("Failed on GetAsync(.."id..") to BannedPlayersStore")
warn(banned)
return nil
end
return banned
end
game.Players.PlayerAdded:Connect(function(player)
if isBanned(player.UserId) then
player:Kick("You cannot join because you have been banned.")
end
end
1 comment
I would have to recode all of my 100+ lines script, isn't there any other way to save each value with a loop to a DataStore?