Before I get started, the way to ban players in the game I’m trying to make is through a GUI. Yes, you heard me, a GUI. To ban players, A player must type in a TextBox, then press a button in order to ban a player, which a remoteEvent with the text inside the textbox is fired towards a ServerScript. After validating that the player is a confirmed admin, the script will attempt to find the player in the server, then update the datastore to ensure the player can never join back again while also kicking the player from the game.
Here are my scripts. Some of them may be heavily shortened.
Button Script
-- VARIABLES
local RS = game:GetService("ReplicatedStorage")
local Player = game.Players.LocalPlayer
local SGUI = script.Parent.Parent.Parent
local Button = SGUI.ScrollingFrame:WaitForChild("BanPlayer")
local banEvent = RS.BanEvent
local debounce = false
local PGUI = Player:WaitForChild("PlayerGui")
--EVENT
Button.MouseButton1Click:Connect(function()
local text = PGUI.AdminPanel.ScrollingFrame.BanPlayer
if debounce == false then
debounce = true
print("SUCCESS")
banEvent:FireServer(text.Text)
task.wait(0.25)
debounce = false
end
end)
Admin Panel
--VARIABLES
local rS = game:GetService("ReplicatedStorage")
local SSS = game:GetService("ServerScriptService")
local SG = game:GetService("StarterGui")
local DS = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local BanStore = DS:GetDataStore("BanStore")
local BanEvent = rS.BanEvent
--BANNING PLAYERS
BanEvent.OnServerEvent:Connect(function(Player, target)
print(Player.Name)
print(Player.UserId)
print(target)
if PanelWhitelist[Player.UserId] then
print("SUCCESS")
for i, player in pairs (Players:GetPlayers()) do
if player.UserId == target then
BanStore:SetAsync(player.UserId, true)
player:Kick("???")
end
end
elseif not PanelWhitelist[Player.UserId] then
print("SUCCEEDED")
Player:Kick("NICE EXPLOITS.")
end
end)
Server Script for banning players that attempt to join again
local DataStore = game:GetService("DataStoreService")
local module = require(script.ModuleScript)
local Players = game:GetService("Players")
local BanStore = DataStore:GetDataStore("BanStore")
function banned(Player)
Player:Kick("Permanently Banned!")
end
game.Players.PlayerAdded:Connect(function(player)
local BanData = BanStore:GetAsync(player.UserId)
if BanData then
banned(player)
end
end)
The main problem currently lies in the Admin Panel script. Although the values do pass, the player (target
) in the adminpanel script as the 2nd variable for the function does not seem to be banning the player according to their userid. Even though I have correctly entered the player’s UserId, the player isn’t getting kicked. It’s not the DataStore causing the problem, I have commented it out when I was testing the ban and I do not know what’s the problem.
In addition, I have a possible worry about the way of saving the data being unreliable. SetAsync is known to not care about data at all and overwrite everything in it’s path, compared to UpdateAsync. However, I have read what SetAsync does, which sets a value, but I have huge amounts of confusion revolving around DataStore, as it is something I have not yet learned and is challenging to figure out, especially when making a DataStore script for the first time without knowing what to do (Infact, I’ve had to use a YouTube video that has a ban system tutorial for the code for the third one and 2nd one however I have a few doubts about the code due to it’s reliability and including that I have no knowledge of how a DataStore works).
I do not know if it’s the most efficient method. Thus, I’m asking for help. I’m new to DataStores, but passing values? Not so much, although I could get better. That’s why I’m asking for help. I haven’t been able to fix the problem and I do not know much about DataStores, which is one of my hardest challenges I have yet to learn and use. If anyone would like to help, please do!