I’m not that good with datastores but I made a script that bans people when an admin enters their username and a reason and when the admin clicks the ban button, the player gets banned. The ban part of the script works but what doesn’t work is the unban part. I tried using RemoveAsync(), but it keeps giving me the error message “argument 1 missing or nil”. Heres the script:
game.ReplicatedStorage.Ban.OnServerEvent:Connect(function(player, rsn, plr)
local success, errormessage = pcall(function()
datastore:SetAsync(plr.UserId, true)
end)
if success then
print(plr.." is now banned!")
end
plr:Kick(rsn)
end)
game.Players.PlayerAdded:Connect(function(player)
local id = player.UserId
local banned
local success, errormessage = pcall(function()
banned = datastore:GetAsync(id)
end)
if banned == true then
player:Kick("You're banned from the game!")
end
end)
game.ReplicatedStorage.UnBan.OnServerEvent:Connect(function(player, plr)
datastore:RemoveAsync(plr.UserId, false)
print(plr.." is now unbanned!")
end)
When you do SetAsync, and the key doesn’t exist, it will create a key with the value. A Datastore is like a table, where there is a key and a value. You can think of it like this: