With the recent discontinuation of the “OnUpdate” API for GlobalDataStores, I was forced to learn how the Messaging Service works.
So now I am using both the DatastoreService and MessagingService collaboratively, though there is a certain thing I’m trying to wrap my head around, maybe I’ve been looking at it too long and the solution is simple but without further ado:
repeat
succ = pcall(function()
playerBanned = banData:GetAsync("user_"..pl.UserId)
end)
if succ then break end
wait()
until succ
if playerBanned then
wait(0.1)
pl:Kick("You have been banned.")
playersWhoJoined[pl.Name] = " (Banned)"
warn("[PLAYERS]",pl.Name," joined unsuccessfully.")
return
end
if not pl.Parent then return end
playersWhoJoined[pl.Name] = ""
highestPlayerCount = math.max(highestPlayerCount,#game.Players:GetPlayers())
local banCon
banCon = MS:SubscribeAsync("CrossBan", function(val)
if val.Data then
banCon:disconnect()
pl.UserId:Kick("You have been banned.")
playersWhoJoined[pl.Name] = " (Banned)"
warn("[PLAYERS]",pl.Name," joined unsuccessfully.")
end
end)
--[[banCon = banData:OnUpdate("user_"..pl.UserId,function(val) --Roblox Broke OnUpdate
if val then
banCon:disconnect()
pl:Kick("You have been banned.")
playersWhoJoined[pl.Name] = " (Banned)"
warn("[PLAYERS]",pl.Name," joined unsuccessfully.")
end
end)]]
banCheckers[pl.Name] = banCon
This is a snip-bit of the Datascript I have for the Banlist and partially how I did it with the Datastore system before it was patched out. Now, when I use my admin script to ban someone it adds them to the Banlist Data and notifies the script that they’ve been banned in that server, however I am pulling my hair out on how to actually ban them outright without kicking everyone else from the game because it doesn’t specify a player ID like it used to, I’m sure there’s a work around to this but I am stumped.
Admin Command:
local args = {...}
args = operators(speaker,args)
if #args >= 1 then
for i,v in pairs(args) do
local id = tonumber(v)
local player = getPlayer(v)
if player then
if not Admins[player.UserId] then
local key = "user_"..player.userId
local succ
repeat
succ = pcall(function()
banData:SetAsync(key,speaker.Name)
MS:PublishAsync("CrossBan", key)
end)
if succ then break end
wait()
until succ
game.ServerStorage.Requests.DiscordEvent:Fire("mod",player.Name.." ("..player.userId..") was banned by "..speaker.Name..".",player.userId)
player:Kick("You have been banned from the game, courtesy of "..speaker.Name.."... That wasn't very bright, was it?")
end
elseif id then
if not Admins[id] then
local key = "user_"..id
local succ
repeat
succ = pcall(function()
banData:SetAsync(key,speaker.Name)
MS:PublishAsync("CrossBan", key)
end)
if succ then break end
wait()
until succ
game.ServerStorage.Requests.DiscordEvent:Fire("mod",game.Players:GetNameFromUserIdAsync(id).." ("..id..") was banned by "..speaker.Name..".",id)
end
end
end
end
end
Please let me know if you have a solution.