Hello all! I am trying to make an unban script in my game but when I use the unban command on someone banned, the unban command does not work. Anyone got suggestions to fix this? Thanks!
Try calling removeAsync(ID) instead of setAsync.
maybe not try setting it to nil? maybe thats the problem. or just as Ani stated use RemoveAsync(plrtoUnbanId)
local dss = game:GetService("DataStoreService")
local pBanDS = dss:GetDataStore("PermanentBanData")
local tBanDS = dss:GetDataStore("TempBanData")
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg)
local split = msg:split(" ")
if plr:GetRankInGroup(groupId) >= minimumRankToUseCommand and split[1] == commandToUse then
local plrToUnBan = split[2]
local plrToUnBanId = game.Players:GetUserIdFromNameAsync(plrToUnBan)
pcall(function()
pBanDS:SetAsync(tostring(plrToUnBanId) .. "-PermanentBanData", nil)
tBanDS:SetAsync(tostring(plrToUnBanId) .. "-TempBanData", nil)
end)
end
end)
end)
GetUserIdFromNameAsync
is a yielding function and needs to be wrapped in a pcall
function to prevent errors from halting the script. Lastly, when calling SetAsync
, it’s good practice to convert the plrToUnBanId
to a string with tostring()
to prevent potential errors due to incorrect data types.
However, note that manipulating datastore values like this can be risky, and it’s best to test your scripts thoroughly before deploying them in a live game environment.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.