My GUI for the message will not go on screen because it does not even get past FireAllClients. I did add print statements it did not print inside the localscript I fired to. I would appreciate help on this and please tell me what I did wrong.
--ServerScript Command
commands.msg = function(sender, args)
local message = args[1]
if message then
local player = CommandsModule.FindPlayer()
script.Parent.ClientCommand:FireAllClients(player, message)
end
end
--ModuleScript
local commandsModule = {}
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)
end
return commandsModule
--LocalScript
local CommandsModule = require(script.Parent)
script.Parent:WaitForChild("ClientCommand").OnClientEvent:Connect(function(player, msg)
CommandsModule:MessageCommand(player, msg)
end)
commands.msg = function(sender, args)
local message = args[1]
if message then
script.Parent.ClientCommand:FireAllClients(message)
end
end
And your client side:
local CommandsModule = require(script.Parent)
local player = game.Players.LocalPlayer
script.Parent:WaitForChild("ClientCommand").OnClientEvent:Connect(function(msg)
CommandsModule:MessageCommand(player, msg)
end)
Alright then replace your server side script with this:
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(text)
if string.sub(text,1,5) == ":msg " then
local message = string.split(string.sub(text,6,#text)
if message then
script.Parent.ClientCommand:FireAllClients(message)
end
end
end)
end)
local commands = {}
--local CommandsModule = require(script.Parent.CommandsModule)
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)
for _, v in pairs(admins) do
if v == player.Name then -- If their an admin
return true
end
end
return false
end
commands.m = function(sender, args)
local message = args[1]
if message then
for _, player in pairs(game.Players:GetPlayers()) do
script.Parent.ClientCommand:FireAllClients(player, message)
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)
Alright after looking at your code here, I figured that your problem might be at the line where you wrote local cmdName = cmd[2]. When you are splitting the string in the line where you wrote local cmd = slashCommand:split(prefix), it will exclude the prefix from the table returned, so the value of cmd[2] will be empty. You should replace it with local cmdName = cmd[1].