I want to achieve my admin commands
My commands will not find my cmd variable string it only finds this one:
-green = found
-red = not found
I have searched how to find strings on a remote event on devforum.roblox.com and youtube.com
So I am trying to make my fly command call the command but when I fire my cmd variable it only works for my message command / m. I do not know if it only finds it as “msg” because of it not waiting for me to call the command or it just wont work. I need help please…
--ModuleScript
local commandsModule = {}
local body
function commandsModule.FindPlayer()
for _, player in pairs(game.Players:GetPlayers()) do
return player
end
end
function commandsModule.MessageCommand(player, result)
local messageGui = script.MessageGui
local messageClone = messageGui:Clone()
messageClone.Parent = player:WaitForChild("PlayerGui")
messageClone.MessageFrame.Message.Text = tostring(result)
local image = game.Players:GetUserThumbnailAsync(player.UserId, Enum.ThumbnailType.HeadShot,Enum.ThumbnailSize.Size100x100)
messageClone.MessageFrame.PlayerImage.Image = image
print("Message Sent Successfully")
wait(5)
messageClone:Destroy()
end
function commandsModule.FlyCommand(player)
local char = player.Character
local humanoid = char:FindFirstChild("Humanoid")
body = Instance.new("BodyVelocity")
body.Name = "FlyVelocity"
body.Parent = player.Character.HumanoidRootPart
body.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
body.Velocity = Vector3.new(0,0,0)
end
function commandsModule.UnflyCommand()
body:Destroy()
end
return commandsModule
--ServerScript
local commands = {}
local cmd
--local CommandsModule = require(script.Parent.CommandsModule)
local ClientCommand = game.ReplicatedStorage:WaitForChild("ClientCommand")
local admins = {
"FreeFlyHaker56"
}
local prefix = ":"
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 isAdmin(player)
if table.find(admins,player.Name) then
return true
end
return false
end
commands.m = function(sender, args)
cmd = "msg"
for index,arg in pairs(args) do
print(index,arg)
end
local message = args[1]
if message then
print("Message Found")
ClientCommand:FireAllClients(message,cmd)
print("Remote Event Fired")
end
end
commands.fly = function(sender, args)
cmd = "fly"
local playerToFly = args[1]
if playerToFly then
local player = findPlayer(playerToFly)
if player then
ClientCommand:FireAllClients(cmd)
end
end
if args[1] == "me" then
if sender then
ClientCommand:FireAllClients(cmd)
end
end
end
commands.unfly = function(sender, args)
cmd = "unfly"
local playerToUnfly = args[1]
if playerToUnfly then
local player = findPlayer(playerToUnfly)
if player then
ClientCommand:FireAllClients(cmd)
end
end
if args[1] == "me" then
if sender then
ClientCommand:FireAllClients(cmd)
end
end
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(prefix)
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)
--LocalScript
local CommandsModule = require(game.ReplicatedStorage:WaitForChild("CommandsModule"))
local ClientCommand = game.ReplicatedStorage:WaitForChild("ClientCommand")
local player = game.Players.LocalPlayer
ClientCommand.OnClientEvent:Connect(function(msg, cmd)
if cmd == "msg" then
print(cmd)
CommandsModule.MessageCommand(player, msg)
elseif cmd == "fly" then
print(cmd)
CommandsModule.FlyCommand(player)
elseif cmd == "unfly" then
print(cmd)
CommandsModule.UnflyCommand()
end
end)