-
What do you want to achieve?
I want to get a unban script that removes a player from the datastore. -
What is the issue?
I’m not sure how to combat the player removing part of the datastore. -
What solutions have you tried so far?
I’ve looked around the devforum and I havent found any useful solutions.
Below is the ban script. I’ve already tried reverting the ban command to an unban command but the player isn’t in the game because they can’t be.
local dds = game:GetService("DataStoreService")
local dataname = "blk-2"
local blkListDatastore = dds:GetDataStore(dataname)
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(msg)
local splitMsg = string.split(msg, " ")
local cmd = splitMsg[1]
if splitMsg[1] == "ban"then
local target = game.Players:FindFirstChild(splitMsg[2])
if target then
local success, errorMessage = pcall(function()
blkListDatastore:SetAsync(target.UserId, true)
print("added to datastore")
player:Kick("L")
end)
if not success then
warn("Failed to add player to the datastore:", errorMessage)
end
end
end
end)
end)
game.Players.PlayerAdded:Connect(function(target)
local success, data = pcall(function()
return blkListDatastore:GetAsync(target.UserId)
end)
if success then
if data == nil then
-- Player is not in the datastore
print("not in datastore")
else
target:Kick("in datastore")
end
else
warn("Failed to retrieve data:", data)
end
end)