So I followed alvin blox’s admin commands tutorial and it was working at first it did work but now it doesn’t seem to work at all. I’ve tried to debug it to the best of my ability but I could fix the issue.
local ChatService = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner").ChatService)
local admins = {
"ThunderCobra48"
}
local prefix = "/"
local commands = {}
local function FindPlayer(name)
for i, player in pairs(game.Players:GetPlayers()) do
if string.lower(player.Name) == name then
return player
end
end
return nil
end
local function ColorChat(sender, args)
local player = sender
local speaker = ChatService:GetSpeaker(player.Name)
local r = args[1]
local g = args[2]
local b = args[3]
if speaker then
speaker:SetExtraData("ChatColor", Color3.new(r, g, b))
end
end
commands.tp = function(sender, arguments)
for i, playerName in pairs(arguments) do
print(playerName)
end
local playerToTeleport = arguments[1]
local playerToTpTo = arguments[2]
if playerToTeleport.Name and playerToTpTo.Name then
local plrToTp = FindPlayer(playerToTeleport.Name)
local plrToTpTo = FindPlayer(playerToTpTo.Name)
if plrToTpTo and plrToTp then
plrToTp.Character.HumanoidRootPart.CFrame = plrToTpTo.Character.HumanoidRootPart.CFrame
print("sucessfully moved")
end
end
end
commands.color = function(sender, arguments)
print("Command run")
ColorChat(sender, arguments)
end
local function isAdmin(player)
for _, v in pairs(admins) do
if v == player.Name then
return true
end
end
return false
end
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(message, recipient)
if isAdmin(player) then
message = string.lower(message)
local splitString = message:split(" ")
local slashCommand = splitString[1]
local cmd = slashCommand:split("/")
local cmdName = cmd[2]
if commands[cmdName] then
local args = {}
for i = 2, #splitString, 1 do
table.insert(args,splitString[i])
end
commands[cmdName](player,args)
end
end
end)
end)
Alright, I figured out the problem. along with the tonumber problem I already adressed,
this is delaying the rest of the script from running making the PlayerAdded event not be called for the first person in the server or few first people if they join around the same time. There are 2 solutions to this. Moving the functions with colorchat to AFTER the PlayerAdded event (and the ChatService variable), or have the ChatService as nil and adressing it inside of a coroutine or the function itself.
here is the script with how I edited it:
local admins = {
"ThunderCobra48"
}
local prefix = "/"
local commands = {}
local function FindPlayer(name)
for i, player in pairs(game.Players:GetPlayers()) do
if string.lower(player.Name) == name then
return player
end
end
return nil
end
commands.tp = function(sender, arguments)
for i, playerName in pairs(arguments) do
print(playerName)
end
local playerToTeleport = arguments[1]
local playerToTpTo = arguments[2]
if playerToTeleport.Name and playerToTpTo.Name then
local plrToTp = FindPlayer(playerToTeleport.Name)
local plrToTpTo = FindPlayer(playerToTpTo.Name)
if plrToTpTo and plrToTp then
plrToTp.Character.HumanoidRootPart.CFrame = plrToTpTo.Character.HumanoidRootPart.CFrame
print("sucessfully moved")
end
end
end
local function isAdmin(player)
for _, v in pairs(admins) do
if v == player.Name then
return true
end
end
return false
end
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(message, recipient)
if isAdmin(player) then
message = string.lower(message)
local splitString = message:split(" ")
local slashCommand = splitString[1]
local cmd = slashCommand:split("/")
local cmdName = cmd[2]
if commands[cmdName] then
local args = {}
for i = 2, #splitString, 1 do
table.insert(args,splitString[i])
end
commands[cmdName](player,args)
end
end
end)
end)
local ChatService = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner").ChatService)
local function ColorChat(sender, args)
local player = sender
local speaker = ChatService:GetSpeaker(player.Name)
local r = tonumber(args[1])
local g = tonumber(args[2])
local b = tonumber(args[3])
if speaker then
speaker:SetExtraData("ChatColor", Color3.new(r, g, b))
end
end
commands.color = function(sender, arguments)
print("Command run")
ColorChat(sender, arguments)
end