Ban script help

Basically I was trying to do a ban script with a reason that people can type when they are doing the ban command, it kicks the player with the reason but it doesn’t save in the data store, or just doesn’t work.

Ban Server:

		local success, errormsg = pcall(function()
			banDS:SetAsync({plrUserId, context}, true)
		end)

Ban Handler:

	local banned 
	local success, errormsg = pcall(function()
		banned = banDS:GetAsync(plrUserId)
	end)
	
	if banned == true and plr:GetRankInGroup(groupID) <= 249 then
		local reason = banned[2]
		wait()
		plr:Kick("Banned. "..reason)
	end

The first argumemtn should be a string, but you are giving it a table.

1 Like

That way (

		local success, errormsg = pcall(function()
			banDS:SetAsync(plrUserId, {context}, true)
		end)

)
it doesn’t kick the player at all

I believe it should be

banDS:SetAsync(plr.UserId, {context, true})

Now it kicks the player, but the ban handler doesn’t work. When a player rejoins the game, he’s unbanned. (he doesn’t get kicked)

Do you have something that checks if they’re banned when they join?

game.Players.PlayerAdded:Connect(function(plr)
	local plrUserId = plr.UserId
	
	if manualBan[plrUserId] then
		plr:Kick("Banned.")
	end
	
	local banned 
	local success, errormsg = pcall(function()
		banned = banDS:GetAsync(plrUserId)
	end)
	
	if banned == true and plr:GetRankInGroup(groupID) <= 249 then
		local reason = banned[2]
		wait()
		plr:Kick("Banned. "..reason)
	end
end)

I think banned is the table that’s returned that you stored earlier by banning the player. You stored the table in this order: {context, true} so table[1] is the ban reason and table[2] is the banned status (true)

if banned[2] == true and plr:GetRankInGroup(groupID) <= 249 then
    local reason = banned[1]
1 Like

still doesn’t work
30 chsrs ss
EDIT: it works, it may have not updated the first time but the second one it worked perfectly, now i have to ask a friend to unban me

Doesn’t it check the group rank so it doesn’t ban the owner? You could just include yourself in the never-banned list and unban yourself