Banned from my own game?

**testing out a custom admin panel, ban script works but unban script doesn’t, can anyone please help **

local banDS = game:GetService("DataStoreService"):GetDataStore("Bans")
local mods = {900293979}

game:GetService("Players").PlayerAdded:Connect(function(plr)
	local key = "-Banned" ..plr.UserId
	local success, val = pcall(function()
		return banDS:GetAsync(key)
	end)
	
	if(success) then
		if(val) then
			if(val[2] == true) then
				plr:Kick("\n You are permenetly banned. \n Reason: \n" .. val[1])
			end
		end
	else
		print("An error occured while checking" .. plr.UserId .. " " .. plr.Name)
		warn(val)
	end
end)

game:GetService("ReplicatedStorage").BanRequest.OnServerEvent:Connect(function(mod, plr, reason)
	if (table.find(mods, mod.UserId)) then
		if(reason ~= false) then
		local key = "-Banned" .. plr.UserId
		local success, err = pcall(function()
			banDS:SetAsync(key,{reason, true})
		end)
			plr:Kick("\n You are permenetly banned. \n Reason: \n" .. reason)
		else
			local success, err = pcall(function()
				banDS:RemoveAsync("-Banned" .. plr.UserId)
			end)
			if (not success) then
				print("unable to unban".. plr.Name .. "UserId: " .. plr.UserId)
				warn(err)
			end
		end
	end
end)

Go into the game settings on the web site and revert back to an older version of the game from before you added the admin script.

Why would you test ban your owner account?

Another option would be to use Studio to edit the datastore and delete the ‘ban’ data.

Another option, disable this script and publish the game again.

Just make the name of the ban data store something else like “banned” or “banlist” etc

1 Like

Make a new script and paste this inside:

local BanDS = game:GetService("DataStoreService"):GetDataStore("Bans")

BanDS:SetAsync("-Banned" ..308764396, nil) -- If you're using another account change the id for that one

####### ###

1 Like

Yes, as @shipmaster2410 says, just change that to “Bans2” and start a new datastore.

1 Like

still confused. how should I change Bans2 to start a new datastore?

local banDS2 = game:GetService("DataStoreService"):GetDataStore("unBans")
game:GetService("ReplicatedStorage").BanRequest.OnServerEvent:Connect(function(mod, plr, reason)
	if (table.find(mods, mod.UserId)) then
		if(reason ~= false) then
		local key = "-Banned" .. plr.UserId
		local success, err = pcall(function()
			banDS2:SetAsync(key,{reason, true})
		end)
			plr:Kick("\n You are permenetly banned. \n Reason: \n" .. reason)
		else
			local success, err = pcall(function()
				banDS2:RemoveAsync("-Banned" .. plr.UserId)
			end)
			if (not success) then
				print("unable to unban".. plr.Name .. "UserId: " .. plr.UserId)
				warn(err)
			end
		end
	end
end)

tried that, still didnt work. did I do something wrong?

Don’t change the variable name, that is irrelevant, change the datastore name:
image

bans and unbans share the same local script

“bans” is the name of the datastore with your userid banned within its data. If you change the script to look for a datastore named “bans2” it will generate a new datastore with nothing in it.

This was @shipmaster2410 's idea, i’d give him the solution.

1 Like

thank you. I got the unban script to work as well

3 Likes