Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Unbanning player with datastores?

I need help with datastores. I figured out how to ban a player with datastores, but how would I unban that player? This below is how the ban works and how a person gets banned in-game. If the number is greater than 0, then the player is banned. How would I write code that would unban the player without the player being in the game?

_G["bandata"] = "byeskid"
local banstore = game:GetService("DataStoreService"):GetDataStore(_G.bandata)

function onPlayerEntered(player)
	local ban = banstore:GetAsync(player.userId .. "_ban")
	if ban and ban > 0 then
		player:Kick()
	end
end
		
--------BAN-PLAYER--------

function Ban()
	local name = script.Parent.Player.Text
	if name and not script.Parent.Parent:FindFirstChild("Pass") then
		local banned = game.Players:FindFirstChild(name)
		if banned then
			banstore:SetAsync(banned.userId .. "_ban", 3)
			banned:Kick()
		end
		script.Parent.Player.Text = " "
	end
end
script.Parent.Ban.MouseButton1Click:connect(Ban)

1 answer

✓ Accepted answer

"If the number is greater than 0, then the player is banned."

So, you can simply save their value as 0 again.

function UnBan()
	local name = script.Parent.Player.Text
	name = game.Players:GetUserIdFromNameAsync(name)
	if name and not script.Parent.Parent:FindFirstChild("Pass") then
		banstore:SetAsync(name.."_ban",0)
	end
end

script.Parent.UnBan.MouseButton1Click:Connect(UnBan)

2 comments

1

Addendum, if you want to be able to use the name you can use http://wiki.roblox.com/index.php?title=API:Class/Players/GetUserIdFromNameAsync

0

Nice tip ;D

This discussion is preserved as it was. New answers, comments, and votes are closed.