I. What do you want to achieve?
Custom “:setmessage” command.
II. What is the issue?
I don’t know, script isn’t working with no errors.
III. What solutions have you tried so far?
Tried to do StarterGui instead of PlayerGui but failed.
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)
[EDIT i]
I attached an image of the location of the script and the gui.
[EDIT ii]
I wrote "if player.Name == “airsoft561"” to test a criteria and to test if it only runs if the criteria is met.
[EDIT iii]
“titl” stands for “title” (textlabel in gui)
You should use RemoteEvents. Your script won’t work since its setting the text everytime a player joins. Plus, manipulating UI’s on the Server is Bad Practice and should be avoided.
I can’t use remoteevents because how can I fire an event that sets the text of a TextLabel that has the arguments I want it to set it in another script.
MAIN CODE (Script in ServerScriptService, “CustomAdminCmds”)
-- [ STARTING VARIABLES ] --
local commands = {}
local prefix = ":"
local RS = game:GetService("ReplicatedStorage")
local Remote = RS:WaitForChild("RemoteEvent")
-- [ 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]
Remote:FireAllClients(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)
UI CODE (LocalScript inside of the Gui)
-- [ STARTING VARIABLES ] --
local RS = game:GetService("ReplicatedStorage")
local Remote = RS:WaitForChild("RemoteEvent")
-- [ MAIN CODE ] --
Remote.OnServerEvent:Connect(function(MessageToSet)
script.Parent.MainFrame.msg.Text = (MessageToSet)
end)