Hi, I am making a game and I have a custom admin script but I have a command that will show a screen message when an admin says “/message MessageText” then it will say “MessageText” on everybodys screens but the problem is that I cant get it to only work for admins so this means that anybody can run this command instead of just admins here is the code:
game.Players.PlayerAdded:Connect(function(dude, sender, arguments)
dude.Chatted:Connect(function(String)
if string.find(String, "/message") then
local Message = string.split(String, "/message")
local M = Instance.new("Message")
M.Text = dude.Name .." Said: ".. Message[2]
M.Parent = game.Workspace
task.wait(5)
M.Parent = nil
end
end)
end)
This is the code that shows the message here is the full script:
--//Variables
local commands = {}
local prefix = "/"
--//Admins
local admins = {
"PuffyJasonrocks84";
"1BATGIRLL"
}
--//FindsPlayers
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
--//ChecksForAdmins
local function isAdmin(player)
for _, v in pairs(admins) do
if v == player.Name then
return true
end
end
return false
end
--//BanPlayerCode --//Bans Are Permanent And Can't Be Reversed With This Code!!!!
local DataStoreService = game:GetService("DataStoreService")
local BannedPlayersData = DataStoreService:GetDataStore('BannedPlayers')
local Players = game:GetService("Players")
local Trigger = '/Ban '
local AD = {'PuffyJasonrocks84'}
local Banned = {}
Players.PlayerAdded:Connect(function(player)
local PlayerId = player.UserId
if Banned[PlayerId] then
player:Kick("You are banned")
end
local Data
local success, errormessage = pcall(function()
Data = BannedPlayersData:GetAsync(PlayerId)
end)
if Data == true then
player:Kick("You are banned")
end
player.Chatted:Connect(function(Chat)
local Check = string.sub(Chat, 1, 5)
if string.match(Trigger, Check) then
local FIND = string.sub(Chat, 6, #Chat)
if Players:FindFirstChild(FIND) then
for _,v in pairs(AD) do
if player.Name == v then
local bannedplayer = Players:FindFirstChild(FIND)
if bannedplayer then
local bannedplayerUserId = bannedplayer.UserId
BannedPlayersData:SetAsync(bannedplayerUserId, true)
task.wait(1)
Players:FindFirstChild(FIND):Kick('You Have Been Banned Permanently by An Admin!')
end
end
end
end
end
end)
end)
--//CustomCommands //PutCustomCommandsUnderThis
commands.tp = function(sender, arguments)
print("TP Function Fired by "..sender.Name)
for i, playerName in pairs(arguments) do
print(playerName)
end
local playerToTeleportName = arguments[1]
local playerToTeleportToName = arguments[2]
if playerToTeleportName and playerToTeleportToName then
local plrToTp = findplayer(playerToTeleportName)
local plrToTPTo = findplayer(playerToTeleportToName)
if plrToTp and plrToTPTo then
plrToTp.Character.HumanoidRootPart.CFrame = plrToTPTo.Character.HumanoidRootPart.CFrame
print("Successfully Moved!")
end
end
end
commands.kill = function(sender, arguments)
print("Kill Player Command Fired By "..sender.Name)
local playertokill = arguments[1]
local playersent = arguments[2]
if playertokill then
local plr = findplayer(playertokill)
if plr then
plr.character.Humanoid.Health = 0
print(playertokill.." Was Killed By "..sender.Name)
end
end
end
commands.dog = function(sender, arguments)
print("dog Command Fired By "..sender.Name)
local playertodog = arguments[1]
local playersent = arguments[2]
if playertodog then
local plr = findplayer(playertodog)
if plr then
plr.character.Shirt:Destroy()
plr.character.Pants:Destroy()
print("Successfuly Dogged "..playertodog)
end
end
end
commands.kick = function(sender, arguments)
print("Kick Command Has Been Fired")
local playertoban = arguments[1]
local timeofban = arguments[2]
if playertoban then
local plr = findplayer(playertoban)
if plr then
plr:Kick("You Have Been Kicked!")
end
end
end
game.Players.PlayerAdded:Connect(function(dude, sender, arguments)
dude.Chatted:Connect(function(String)
if string.find(String, "/message") then
local Message = string.split(String, "/message")
local M = Instance.new("Message")
M.Text = dude.Name .." Said: ".. Message[2]
M.Parent = game.Workspace
task.wait(5)
M.Parent = nil
end
end)
end)
commands.speed = function(sender, arguments)
print("Speed Command Fired By"..sender.Name)
local playerToGiveSpeedTo = arguments[1]
local amountofspeedtogive = arguments[2]
if playerToGiveSpeedTo then
local plr = findplayer(playerToGiveSpeedTo)
if plr then
plr.Character.Humanoid.WalkSpeed = tonumber(amountofspeedtogive)
print(playerToGiveSpeedTo.." was given WalkSpeed "..amountofspeedtogive)
end
end
end
--//ConnectingTheMessages
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(message,recipient)
if isAdmin(player) then
message = string.lower(message)
local spitString = message:split(" ")
local slashCommand = spitString[1]
local cmd = slashCommand:split(prefix)
local cmdName = cmd[2]
if commands[cmdName] then
local arguments = {}
for i = 2, #spitString, 1 do
table.insert(arguments,spitString[i])
end
commands[cmdName] (player,arguments)
end
end
end)
end)
Thanks.