Script doesn't work with no errors

  1. What do you want to achieve?
    I want to make a setmessage command that only I can use.
  2. What is the issue?
    I don’t know, I’ve checked the output and the script it self for errors but it doesn’t work. The gui doesn’t get the message I want it to have.
  3. What solutions have you tried so far?
    I’ve tried putting the variable into paranthesis.

Script:

-- [ STARTING VARIABLES ] --

local commands = {}

local prefix = ":" 

local frame = game.StarterGui:WaitForChild("ScreenGui").MainFrame

-- [ MAIN CODE ] --

-- Setmessage Command --

commands.setmessage = function(sender, args) -- sender: Object - args : Table
	-- What will happen when you run the command.
	print("Setmessage command ran by:")
	print(sender)
	
	for i, playerName in pairs(args) do
		print(playerName)
	end
	
	local MessageToSet = args[1]
	
	frame.msg.Text = MessageToSet
 
end

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(message,recipient)
		if player.Name == "airsoft561" then
		message = string.lower(message) -- TP = tp / Tp = tp etc.
		
		local splitString = message:split(" ") -- {":setmessage","message"}
		
		local prefixCmd = splitString[1] -- ":setmessage"
		
		local cmd = prefixCmd:split(prefix) -- {":","setmessage"} -- another table
		
		local cmdName = cmd[2]
		
		
		if commands[cmdName] then
			
			local args = {} -- Other splited, eg: "yeet" if you did: ":setmessage yeet"
			
			for i = 2, #splitString, 1 do
				table.insert(args,splitString[i])
			end
			
			commands[cmdName](player,args) -- Fires function
				
			end
		else
			print("Player not authorized.")
		end
		-- ":setmessage Interviews" ----> {":setmessage","Interviews"} table
	end)
end)

A screenshot of where the gui is.
image

You’re indexing StarterGui, you should be indexing Player.PlayerGui inside your Player.Chatted signal

https://scriptinghelpers.org/questions/60714/short-questionwhat-are-the-differences-between-playergui-and-startergui

Since your GUI would be located inside of PlayerGui during the game, use this:

game.Players.PlayerAdded:Connect(function(plr)
 
local plrGui = plr:WaitForChild("PlayerGui")
local gui = plrGui:WaitForChild("ScreenGui")
local frame = gui:WaitForChild("MainFrame")

-- Code here
end)

(Place this code inside of the PlayerChatted Event)

Still doesn’t work, no errors.

Updated code:

-- [ STARTING VARIABLES ] --

local commands = {}

local prefix = ":" 

-- [ MAIN CODE ] --

-- Setmessage Command --

commands.setmessage = function(sender, args) -- sender: Object - args : Table
	-- What will happen when you run the command.
	print("Setmessage command ran by:")
	print(sender)
	
	for i, playerName in pairs(args) do
		print(playerName)
	end
	
	local MessageToSet = args[1]
	
	game.Players.PlayerAdded:Connect(function(plr)
 
	local plrG = plr:WaitForChild("PlayerGui")
	local gui = plrG:WaitForChild("ScreenGui")
	local frame = gui:WaitForChild("MainFrame")
	local msgbox = frame:WaitForChild("msg")	
		
	msgbox.Text =  (MessageToSet)
end)
 
end

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(message,recipient)
		if player.Name == "airsoft561" then
		message = string.lower(message) -- TP = tp / Tp = tp etc.
		
		local splitString = message:split(" ") -- {":setmessage","message"}
		
		local prefixCmd = splitString[1] -- ":setmessage"
		
		local cmd = prefixCmd:split(prefix) -- {":","setmessage"} -- another table
		
		local cmdName = cmd[2]
		
		
		if commands[cmdName] then
			
			local args = {} -- Other splited, eg: "yeet" if you did: ":setmessage yeet"
			
			for i = 2, #splitString, 1 do
				table.insert(args,splitString[i])
			end
			
			commands[cmdName](player,args) -- Fires function
				
			end
		else
			print("Player not authorized.")
		end
		-- ":setmessage Interviews" ----> {":setmessage","Interviews"} table
	end)
end)