-
What do you want to achieve?
I want to make a setmessage command that only I can use. -
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. -
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.
