Admin Command Not Working

I want to make a message command

The Issue is my command never gets past a certain point
image

I have went on youtube.com and devforum.roblox.com no solutions.

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)

Please tell me if I am not doing something right.

1 Like

@oSudden @brandonisabillionare @SoAdorablle

First, did you define the module script in your server script. Second, is there any errors in the output?

1 Like

Can I see script analysis and output bar? I could not spot any errors based on the scripts iteself.

1 Like

You’re not passing anything in this function…
I assume this is to find an individual player.

Yes and no errors :grinning_face_with_smiling_eyes:

No I am trying to find them all :grinning_face_with_smiling_eyes: I am new scripter

Ok bro I will show it hold on :grinning_face_with_smiling_eyes:

@brandonisabillionare

@SoAdorablle No I am trying to find all players

For your server side, maybe try this?

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)

Lemme check rn :slight_smile: :grinning_face_with_smiling_eyes:

No it did not work :frowning: :frowning:

@DargoA
@brandonisabillionare
@SoAdorablle

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)

I cant it will ruin my admin commands I will send script

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].

Well I got this from alvinblox but ok