Hello, I am trying to make admin commands using the chat but it doesn’t work.
Script:
local Chat = game:GetService("Chat")
local Players = game:GetService("Players")
local IsPrivateServer = false
local PrivateServerOwner
local AdminList = {}
local Settings = {
Prefix = ":";
}
local function LogMessage(message, logtype)
if logtype == "print" then
game.ReplicatedStorage.Events.LogMessage:FireAllClients(message, logtype)
elseif logtype == "warn" then
game.ReplicatedStorage.Events.LogMessage:FireAllClients(message, logtype)
end
end
local function getServerType()
if game.PrivateServerId ~= "" then
if game.PrivateServerOwnerId ~= 0 then
return "PrivateServer"
else
return "ReservedServer"
end
else
return "StandardServer"
end
end
local function GetPlayer(target)
for i,v in pairs(game.Players:GetPlayers()) do
if v.Name:lower():sub(1,#target) == target:lower() then
return v
end
end
end
local ServerType = getServerType()
if ServerType == "PrivateServer" then
IsPrivateServer = true
PrivateServerOwner = game.PrivateServerOwnerId
table.insert(AdminList, PrivateServerOwner)
end
Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(message)
if IsPrivateServer then
local Character = player.Character
local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
local command = message:lower()
if command:sub(1, 6) == Settings.Prefix .. "admin" and player.UserId == PrivateServerOwner then
local commandplayer = GetPlayer(command:sub(8))
if commandplayer ~= nil then
if table.find(AdminList, commandplayer.UserId) == nil then
table.insert(AdminList, commandplayer.UserId)
elseif command:sub(1, 8) == Settings.Prefix .. "unadmin" and player.UserId == PrivateServerOwner then
local commandplayer = GetPlayer(command:sub(10))
if commandplayer ~= nil then
if table.find(AdminList, commandplayer.UserId) ~= nil then
table.remove(AdminList, commandplayer.UserId)
elseif command:sub(1, 3) == Settings.Prefix .. "to" and table.find(AdminList, player.UserId) ~= nil then
local commandplayer = GetPlayer(command:sub(5))
if commandplayer ~= nil then
local commandcharacter = commandplayer.Character
local HumanoidRootPartcommand = commandcharacter:FindFirstChild("HumanoidRootPart")
if HumanoidRootPart and HumanoidRootPartcommand then
local offset = 5
HumanoidRootPart.CFrame = HumanoidRootPartcommand.CFrame + HumanoidRootPartcommand.CFrame.lookVector * offset
elseif command:sub(1, 6) == Settings.Prefix .. "bring" and table.find(AdminList, player.UserId) ~= nil then
local commandplayer = GetPlayer(command:sub(8))
if commandplayer ~= nil then
local commandcharacter = commandplayer.Character
local HumanoidRootPartcommand = commandcharacter:FindFirstChild("HumanoidRootPart")
if HumanoidRootPart and HumanoidRootPartcommand then
local offset = 5
HumanoidRootPartcommand.CFrame = HumanoidRootPart.CFrame + HumanoidRootPart.CFrame.lookVector * offset
end
end
end
end
end
end
end
end
end
end
end)
end)