I have this script for admin commands:
-- this script is for trolling players by jumpscaring and doing other things in their server
-- Also for kicking and banning them from the game
--Troll command : /e troll {username} {name image}
-- Kick command: /kick {username} {reason}
-- Kick reason must be a singular word or have the words seperated by "_" for example "Stop_Exploiting"
-- Ban command: /ban {username} {reason}
local DataStoreService = game:GetService("DataStoreService")
local playerDataStore = DataStoreService:GetDataStore("PlayerData")
local message = game:GetService("MessagingService")
local admins = {"talis783"}
local commands = {"kick", "ban", "troll", "unban"}
local commandsFunction = {
["/troll"] = function(player, image)
for i,v in pairs(game:GetService("Players"):GetChildren()) do
if v.Name:lower() == player:lower() then
game.ReplicatedStorage.Troll:FireClient(v,image)
end
end
end,
["/kick"] = function(player, reason)
game.Players:FindFirstChild(player):Kick(reason)
end,
["/ban"] = function(player, reason)
game.Players:FindFirstChild(player):FindFirstChild("ToolsSave"):FindFirstChild("BannedCheck").Value = true
task.wait(3)
print(game.Players:FindFirstChild(player):FindFirstChild("ToolsSave"):FindFirstChild("BannedCheck").Value)
game.Players:FindFirstChild(player):Kick("You have been banned for reason: "..reason)
end,
["/unban"] = function(player, DontNeedThis)
local playerId = game.Players:GetUserIdFromNameAsync(player)
local playerData
local success, error = pcall(function()
playerData = playerDataStore:GetAsync(tostring(playerId))
end)
if success then
-- Modify the BannedCheck value to false
if playerData and playerData[3] ~= nil then
playerData[3] = false
-- Save the modified data back to the data store
local saveSuccess, saveError = pcall(function()
playerDataStore:SetAsync(tostring(playerId), playerData)
end)
if saveSuccess then
print("Player data saved successfully.")
else
warn("Failed to save the player's data: " .. saveError)
end
else
warn("Player data not found or BannedCheck value is nil.")
end
else
warn("Failed to access the player's data store: " .. error)
end
end,
}
game.Players.PlayerAdded:Connect(function(plr)
if table.find(admins,plr.Name) then
print("Found plr in [admins] list")
plr.Chatted:Connect(function(plrmessage)
plrmessage = plrmessage:lower():split(" ")
for i = 1, #commands do
if plrmessage[1]:match(commands[i]) then
local func = commandsFunction[plrmessage[1]]
func(plrmessage[2], plrmessage[3])
end
end
end)
end
end)
and this one for my DataStore
local DataStore = game:GetService("DataStoreService")
local PlrDataStore = DataStore:GetDataStore("PlayerData")
local admins = {"talis783"}
game.Players.PlayerAdded:Connect(function(Player)
local ToolsSave = Instance.new("Folder")
ToolsSave.Parent = Player
ToolsSave.Name = "ToolsSave"
local SnowGlobe = Instance.new("StringValue")
SnowGlobe.Parent = ToolsSave
SnowGlobe.Name = "SnowGlobe"
local Flashlight = Instance.new("StringValue")
Flashlight.Parent = ToolsSave
Flashlight.Name = "Flashlight"
local BannedCheck = Instance.new("BoolValue")
BannedCheck.Parent = ToolsSave
BannedCheck.Name = "BannedCheck"
BannedCheck.Value = false
local PlayerData
local succes, ErrorMsg = pcall(function()
local PlayerId = Player.UserId
PlayerData = PlrDataStore:GetAsync(PlayerId)
end)
if succes then
if PlayerData then
BannedCheck.Value = PlayerData[3]
print(BannedCheck.Value)
if BannedCheck.Value == true then
--if not table.find(admins, Player.Name) then
task.wait(10)
Player:Kick("You are banned")
--end
end
end
else
warn(ErrorMsg)
end
end)
local function saveData(Player)
local ToolsSave = Player.ToolsSave
local PlayerData = {ToolsSave.SnowGlobe.Name, ToolsSave.Flashlight.Name, ToolsSave.BannedCheck.Value}
local Success, ErrorMsg = pcall(function()
PlrDataStore:SetAsync(Player.UserId, PlayerData)
end)
if not Success then
warn(ErrorMsg)
end
if Success then
end
end
game.Players.PlayerRemoving:Connect(function(Player)
saveData(Player)
end)
game:BindToClose(function()
for _, Player in pairs(game.Players:GetPlayers()) do
saveData(Player)
end
end)
Everything works except the ability to unban someone. I banned myself just to test it and gave myself 10 seconds to unban myself. However the datastore script still thinks i am banned