at this point i have no idea whats wrong even with the banlist command. i try using the banlist command but it says permission denied even when i do have permission i can’t figure out why it’s even doing this cause i don’t see anything wrong. everything else works perfectly fine
local remoteEvent = replicatedStorage.ExecuteCMD
-- Table to store players with permission levels
local playerPermissions = {
["jjphariss"] = "Owner", -- Replace with player usernames and their respective permission levels
["Username2"] = "Admin",
-- Add more usernames and permission levels as needed
}
-- Table to store command handlers
local commandHandlers = {}
-- Define permission levels and their associated commands
local permissionLevels = {
Owner = {"kill", "noclip", "hello", "info", "fire", "cmds","admin", "kick", "ban","unban","banlist"}, -- Owner can use all commands
Admin = {"kill", "hello", "info", "banlist"}, -- Admin can use these commands
Moderator = {"hello", "info", "banlist"}, -- Moderator can use these commands
}
-- Function to check if a player has permission to use a command
local function hasPermission(player, command)
local permissionLevel = playerPermissions[player.Name]
if permissionLevel then
local allowedCommands = permissionLevels[permissionLevel]
if allowedCommands then
for _, allowedCommand in ipairs(allowedCommands) do
if allowedCommand == command then
return true
end
end
end
end
return false
end
-- Function to execute a command
local function executeCommand(player, command, partialName)
-- Check if the player has permission to use the command
if not hasPermission(player, command) then
-- Send a permission denied message to the client
remoteEvent:FireClient(player, "Permission denied.")
return
end
-- Find and execute the command handler
local handler = commandHandlers[command]
if handler then
handler(player, partialName)
else
-- Send an error message for unknown commands
remoteEvent:FireClient(player, "Unknown command: " .. command)
end
end
-- Register a new command handler
function registerCommand(command, handler)
commandHandlers[command] = handler
end
-- Function to find a player by partial name
local function findPlayerByPartialName(partialName)
for _, player in ipairs(game.Players:GetPlayers()) do
if player.Name:lower():match(partialName:lower()) then
return player
end
end
return nil
end
-- kill command
registerCommand("kill", function(player, partialName)
-- Find the target player by partial name
local targetPlayer = findPlayerByPartialName(partialName)
if targetPlayer then
-- Destroy the target player's character
local character = targetPlayer.Character
if character then
character:BreakJoints()
remoteEvent:FireClient(player, "Successfully killed: " .. partialName)
end
else
-- Send an error message if the target player is not found
remoteEvent:FireClient(player, "Player not found: " .. partialName)
end
end)
-- Table to store players who are in "NoClip" mode
local noclipPlayers = {}
-- Function to toggle NoClip mode for a player
local function toggleNoClip(player)
if noclipPlayers[player] then
-- Disable NoClip mode
noclipPlayers[player] = nil
player:LoadCharacter()
remoteEvent:FireClient(player, "NoClip disabled.")
else
-- Enable NoClip mode
noclipPlayers[player] = true
local character = player.Character
if character then
-- Disable collisions for the player's character
for _, object in ipairs(character:GetDescendants()) do
if object:IsA("BasePart") then
object.CanCollide = false
end
end
end
remoteEvent:FireClient(player, "NoClip enabled.")
end
end
-- banlist command
registerCommand("banlist", function(player, partialName)
-- Check if the player has permission to use the command
if not hasPermission(player, "banlist") then
-- Send a permission denied message to the client
remoteEvent:FireClient(player, "Permission denied.")
return
end
local targetPlayer = findPlayerByPartialName(partialName)
-- Fetch and display the list of banned players and their ban times
local dataStore = game:GetService("DataStoreService"):GetDataStore("banData")
local banList = {}
local success, keys = pcall(function()
return dataStore:GetSortedAsync(false, 10) -- Get the first 10 keys (bans)
end)
if success and keys then
for _, key in ipairs(keys) do
local userId = tonumber(string.gsub(key, "ban_", ""))
local banData = dataStore:GetAsync(key)
if banData then
table.insert(banList, {
UserId = userId,
Kicker = banData.Kicker,
BanTime = os.date("%c", banData.BanTime)
})
end
end
end
-- Send the banlist to the client
remoteEvent:FireClient(player, "Banned Players:\n")
for _, banInfo in ipairs(banList) do
local message = "UserID: " .. banInfo.UserId .. " - Banned by: " .. banInfo.Kicker .. " - Ban Time: " .. banInfo.BanTime
remoteEvent:FireClient(player, message)
end
end)
-- ban command
registerCommand("ban", function(player, partialName)
-- Check if the player has permission to use the command
if not hasPermission(player, "ban") then
-- Send a permission denied message to the client
remoteEvent:FireClient(player, "Permission denied.")
return
end
-- Find the target player by partial name
local targetPlayer = findPlayerByPartialName(partialName)
if targetPlayer then
-- Record the ban time using os.time()
local banTime = os.time()
-- Generate a unique ban key for the target player
local banKey = "ban_" .. targetPlayer.UserId
-- Store the ban information in a data store with the unique key
local dataStore = game:GetService("DataStoreService"):GetDataStore("banData")
local success, error = pcall(function()
dataStore:SetAsync(banKey, {
Kicker = player.Name,
BanTime = banTime
})
end)
if not success then
print("Error saving ban player data:", error)
end
-- Kick the target player from the game
targetPlayer:Kick(":Staff Member: >" .. player.Name .. "< banned you from the game")
remoteEvent:FireClient(player, "Successfully banned: " .. partialName)
else
-- Send an error message if the target player is not found
remoteEvent:FireClient(player, "Player not found: " .. partialName)
end
end)
-- unban command
registerCommand("unban", function(player, partialName)
-- Check if the player has permission to use the command
if not hasPermission(player, "unban") then
-- Send a permission denied message to the client
remoteEvent:FireClient(player, "Permission denied.")
return
end
-- Convert the partialName (username) to a UserId
local targetUserId = nil
local success, errorMessage = pcall(function()
targetUserId = game:GetService("Players"):GetUserIdFromNameAsync(partialName)
end)
if not success or not targetUserId then
-- Send an error message if the username is not found
remoteEvent:FireClient(player, "Error: Username not found or invalid.")
return
end
-- Generate the ban key for the target player
local banKey = "ban_" .. targetUserId
-- Attempt to remove the ban information from the data store
local dataStore = game:GetService("DataStoreService"):GetDataStore("banData")
local removeSuccess, removeError = pcall(function()
dataStore:RemoveAsync(banKey)
end)
if removeSuccess then
-- Send a message indicating that the player has been unbanned
remoteEvent:FireClient(player, "Successfully unbanned: " .. partialName)
else
-- Send an error message if there was an issue removing the ban information
remoteEvent:FireClient(player, "Error while trying to unban: " .. removeError)
end
end)
-- ...
-- Function to check if a player is banned
local function isPlayerBanned(player)
local banKey = "ban_" .. player.UserId
local dataStore = game:GetService("DataStoreService"):GetDataStore("banData")
local success, data = pcall(function()
return dataStore:GetAsync(banKey)
end)
return success and data
end
-- PlayerAdded event handler
game.Players.PlayerAdded:Connect(function(player)
if isPlayerBanned(player) then
-- The player is banned, get the ban timestamp
local banKey = "ban_" .. player.UserId
local dataStore = game:GetService("DataStoreService"):GetDataStore("banData")
local success, data = pcall(function()
return dataStore:GetAsync(banKey)
end)
if success and data then
local kickerName = data.Kicker
local banTime = os.date("%c", data.BanTime)
player:Kick(":Staff Member: >" .. kickerName .. "< banned you from the game at " .. banTime)
else
print("Error retrieving ban record for", player.Name)
player:Kick("You are banned from the game.")
end
end
end)
-- ...
-- ...
--admin command
registerCommand("admin", function(player, partialName)
-- Check if the player has permission to use the command
if not hasPermission(player, "admin") then
-- Send a permission denied message to the client
remoteEvent:FireClient(player, "Permission denied.")
return
end
-- Find the target player by partial name
local targetPlayer = findPlayerByPartialName(partialName)
if targetPlayer then
-- Grant admin rank to the target player
playerPermissions[targetPlayer.Name] = "Admin" -- Fixed this line to update the target player's permission level
remoteEvent:FireClient(player, "Admin rank given to: " .. partialName)
targetPlayer.PlayerGui.AdminUI.OpenClose.Visible = true
else
-- Send an error message if the target player is not found
remoteEvent:FireClient(player, "Player not found: " .. partialName)
end
end)
--kick command
registerCommand("kick", function(player, partialName)
-- Check if the player has permission to use the command
if not hasPermission(player, "kick") then
-- Send a permission denied message to the client
remoteEvent:FireClient(player, "Permission denied.")
return
end
-- Find the target player by partial name
local targetPlayer = findPlayerByPartialName(partialName)
if targetPlayer then
-- Kick the target player from the game
targetPlayer:Kick(":Staff Member: >" .. player.Name .. "< kicked you from the game")
remoteEvent:FireClient(player, "Successfully kicked: " .. partialName)
else
-- Send an error message if the target player is not found
remoteEvent:FireClient(player, "Player not found: " .. partialName)
end
end)
-- noclip command
registerCommand("noclip", function(player)
-- Check if the player has permission to use the command
if not hasPermission(player, "noclip") then
-- Send a permission denied message to the client
remoteEvent:FireClient(player, "Permission denied.")
return
end
-- Toggle NoClip mode for the player
toggleNoClip(player)
end)
-- Example command handler for "hello" command
registerCommand("hello", function(player)
-- Send a message back to the client
remoteEvent:FireClient(player, "Hello, player!")
end)
--fire command
registerCommand("fire", function(player, partialName)
-- Send a message back to the client
local targetPlayer = findPlayerByPartialName(partialName)
if targetPlayer then
-- Destroy the target player's character
local character = targetPlayer.Character
if character then
--add fire
local fire = Instance.new("Fire")
fire.Color = Color3.new(math.random(), math.random(), math.random()) --change fire color
fire.Size = 10
fire.Parent = character.HumanoidRootPart
end
end
end)
-- Example command handler for "info" command
registerCommand("cmds", function(player)
-- Construct a list of available commands based on the player's permission level
local permissionLevel = playerPermissions[player.Name]
local availableCommands = {}
if permissionLevel then
local allowedCommands = permissionLevels[permissionLevel]
if allowedCommands then
for _, command in ipairs(allowedCommands) do
table.insert(availableCommands, command)
end
end
end
-- Send an info message back to the client with the list of available commands
local message = "Available commands: " .. table.concat(availableCommands, ", ")
remoteEvent:FireClient(player, message)
end)
-- Example command handler for "info" command
registerCommand("info", function(player)
-- Send an info message back to the client
remoteEvent:FireClient(player, "This is an info message.")
end)
-- Function to send a message to a target player using a TextBox in ScreenGui
local function sendMessageToPlayer(player, partialName, message)
-- Find the target player by partial name
local targetPlayer = findPlayerByPartialName(partialName)
if targetPlayer then
-- Get the player's PlayerGui
local playerGui = targetPlayer:FindFirstChild("PlayerGui")
if playerGui then
-- Find the ScreenGui, Frame, and TextBox
local screenGui = playerGui:FindFirstChild("MessageUI")
local frame = screenGui:FindFirstChild("Frame")
local textBox = frame:FindFirstChild("Message")
if screenGui and frame and textBox then
-- Show the ScreenGui and set the message in the TextBox
frame.Visible = true
textBox.Text = message
remoteEvent:FireClient(player, "Message sent to " .. partialName)
else
-- Send an error message if the UI components are not found
remoteEvent:FireClient(player, "Error: UI components not found for " .. partialName)
end
else
-- Send an error message if PlayerGui is not found
remoteEvent:FireClient(player, "Error: PlayerGui not found for " .. partialName)
end
else
-- Send an error message if the target player is not found
remoteEvent:FireClient(player, "Player not found: " .. partialName)
end
end
-- Register the new command handler
registerCommand("message", function(player, partialName, message)
-- Check if the player has permission to use the command
if not hasPermission(player, "message") then
-- Send a permission denied message to the client
remoteEvent:FireClient(player, "Permission denied.")
return
end
-- Call the sendMessageToPlayer function to send the message
sendMessageToPlayer(player, partialName, message)
end)
-- Listen for commands from clients
remoteEvent.OnServerEvent:Connect(function(player, command, partialName)
executeCommand(player, command, partialName)
end)