Admin Panel Help

Hello, I’m on the final strech of making an Admin Panel. Anyways I need help with the ban system. I got an Error saying attempt to index nil with 'SetAsync’

Anyways, heres my code.

local data = game:GetService("DataStoreService"):GetDataStore("BannedUsers")
local configModule = require(script.Admin.panel.Config)
local admins = configModule.adminIDs

local BanMsg = "You have been permenantly banned from this game."

game.Players.PlayerAdded:Connect(function(player)
	if player.UserId == admins then
		local cloneUI = script.Admin:Clone()
		cloneUI.Parent = player.PlayerGui
	end
	local prevData = data:GetAsync(player.UserId)
	if prevData == nil then
		print("Player does not have to be banned!")
		prevData:SetAsync(player.UserId, false)
	elseif prevData == true then
		print("Player is banned.")
		player:Kick(BanMsg)
	end
end)

game.ReplicatedStorage.Ban.OnServerEvent:Connect(function(player, victim, reason)
	local found = game.Players:FindFirstChild(victim)
	
	if found then
		found:Kick(data..reason)
	end
end)

Any help would be great, note the admin variable is from a {} table that has UserIds on who can access the panel.

1 Like
prevData:SetAsync
data:SetAsync

I’ll try it, ty!

devfourm character limit

Try to save ONLY when the player is banned “SetAsync(player.UserId, true)”, because it isn’t necesary save falses values and that I would avoid to save innecesary values.

Finnaly, on the Ban RemoteEvent do you need save the player to ban. I want say:

game.ReplicatedStorage.Ban.OnServerEvent:Connect(function(player, victim, reason)
	local found = game.Players:FindFirstChild(victim)
	
	if found then
                data:SetAsync(player.UserId, true) -- that inserts the player ban to DataStore
		found:Kick(data..reason)
	end
end)

Before I can try that my Whitelist broke, no errors it just didn’t show up.
It’s in the original code, in the module script its like:

local adminConfig = {}

adminConfig.adminIDs = {1485350602} -- Put IDs of admins here -- BE CAREFUL ABOUT WHO YOU GIVE THE PANEL TO.
adminConfig.HasSettingsProduct = false -- If you do have our settings product set this to true and the button position will change so its beside the settings Button.

return adminConfig

What is the error there? I want say: How the system should be works?

Okay so The ScreenGUI is in the Ban/Whitelist script, it checks if the players userID is in the table in the module script, if it is it clones the UI and sets its parent to that players playerGui.

Probably because you’re trying to save data to the prevData variable which doesn’t represent the datastore but instead the value you pulled from it.

Oh, I get it and I had not noticed. You need iterate the admin table list, like this:

game.Players.PlayerAdded:Connect(function(player)
    for _, adminId in pairs(admins) do
        if player.UserId == adminId then
                local cloneUI = script.Admin:Clone()
	        cloneUI.Parent = player.PlayerGui
                break
        end
    end

	local prevData = data:GetAsync(player.UserId)
	if prevData == nil then
		print("Player does not have to be banned!")
		prevData:SetAsync(player.UserId, false)
	elseif prevData == true then
		print("Player is banned.")
		player:Kick(BanMsg)
	end
end)

try that, your error is that you compare a tablelist to userId, and that is not, is really compare the userId to each to admins list, and if found, give the UI.

there is another way, to make that code with less lines, but It doesn’t work for me, i’m talking about the table.find() but I don’t use that, I prefer iterate for each item to table.

I’ll try it out ty!

Character Limit

Aight, the Whitelist worked (tysm for that)
I tried the ban action and it kinda worked, because when I pushed the button I got hit with the error ServerScriptService.Ban Handler:31: attempt to concatenate Instance with string then when I left and redid the test I was banned.

Ok try this!

game.ReplicatedStorage.Ban.OnServerEvent:Connect(function(player, victim, reason)
	local found = game.Players:FindFirstChild(victim)
	
	if found then
        data:SetAsync(victim.UserId, true) -- that inserts the player ban to DataStore
		found:Kick(data..reason)
	end
end)

I made a mistake, in the line that specifies which player to ban, put the ID of the player that sends the signal and not the victim.

If you are banned of game paste the next in the Script in when the DataStore is specified

data:SetAsync(YOUR USER ID HERE, false)

there paste your userId for to be unbanned