Basically i’m trying to make a custom admin module for somewone with a custom admin system. However i encountered an issue whilr making the module. As the tittle name. it break and bypass the pcall protection too. How can i potentially fix this issue?
local MainModule = {}
MainModule.ActiveRanks = {}
-- Services "dont touch"
local ServerScriptService = game:GetService("ServerScriptService")
local DataStoreService = game:GetService("DataStoreService")
local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")
-- !How to set ranks
-- Return the owner of the game use "game.CreatorId"
-- Set the admin DataStore Name
local DatastoreName = "AdminRankStore"
-- Set ranks
local Ranks = {
["Owner"] = {game.CreatorId},
["Devs"] = {1453085560},
["Head Admin"] = {},
["Admin"] = {},
["Moderator"] = {},
["Invited"] = {},
}
-- Please assign the command to a requirment
-- Add Restricted if you don't want the command to be used for the same rank
local Commands = {
["kick"] = {"Moderator","Restricted"},
["ban"] = {"Moderator","Restricted"},
["give"] = {"Head Admin"},
["teleport"] = {"Moderator"},
["fly"] = {"Devs"},
["add"] = {"Devs"},
["spawn"] = {"Devs"},
["invisible"] = {"Moderator"},
["kill"] = {"Devs"},
["rank"] = {"Owner"},
["unrank"] = {"Owner"},
["saverank"] = {"Owner"},
["unsaverank"] = {"Owner"},
["gravity"] = {"Devs"},
["announce"] = {"Admin"},
}
local success,errorm = pcall(function()
-- Set parent back to where its secure
script.Parent.Parent = ServerScriptService
-- Check the eligibility
if TextChatService.ChatVersion == Enum.ChatVersion.LegacyChatService then
warn("LegacyChatService is not eligible, please change the ChatVersion to TextChatService in TextChatService ChatVersion to use Admin")
return MainModule
end
-- Create command folder
local CommandsFolder = Instance.new("Folder",TextChatService)
CommandsFolder.Name = "AdminCommands"
-- Create triggerable commands
for i,v in Commands do
local command = Instance.new("TextChatCommand",CommandsFolder)
command.Name = i
command.PrimaryAlias = "/"..i
task.spawn(function()
command.Triggered:Connect(function(originTextSource: TextSource, unfilteredText: string)
print("triggered")
end)
end)
end
-- Connect to players joigning
Players.PlayerAdded:Connect(function(player)
for i,v in Ranks do
if table.find(v,player.UserId) then
print(i,v)
self.ActiveRanks[table.find(v,player.UserId)] = i
end
end
end)
end)
if errorm then
warn("Admin load fail: "..errorm)
end
return MainModule