So I'm working with the lua chat system and I have a little command that is supposed to make the bot say what I say. For ex: .say hello world. It should say hello world, but it doesn't.
Here is what I'm working with:
local whitelisted = {game.CreatorId} local whitelist_enabled = true -- for the one above ^^^ local prefix = "." local function chat(plr,msg) local ChatService = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner"):WaitForChild("ChatService")) if not ChatService:GetChannel("All") then while true do local ChannelName = ChatService.ChannelAdded:Wait() if ChannelName == "All" then break end end end local System = ChatService:AddSpeaker("Admin") System:SetExtraData("ChatColor", Color3.fromRGB(59, 0, 255)) System:JoinChannel("All") local function chat(plr,msg) if whitelist_enabled then if not table.find(whitelisted,plr.UserId) then return end end local message if string.sub(msg,1,3) == "/e " then message = string.sub(msg,4) else message = msg end local s = string.split(message," ") if s[1] == prefix.."say" then System:SayMessage("".. s[2] .. "" .. s[3]) end end
Okay so, when someone chats, the message gets broken into 3 strings.
string 1 would be the type of command, such as: spawn or say.
string 2 would be what to spawn or say, such as: .spawn adminprinter or .say hello world.
string 3 would be the rest of the sentence for the .say command.
I hope I gave enough information for someone to help me. Thank you for your time. - Zeta
Your problem might just be that your using arguments and splitting them with spaces. If what your saying, and it is; "hello world" is two words separated the same way as arguments, it will think " world" is the 3rd argument.
To fix it, you can do many things.
You can separate arguments and sentences differently.
Though, I suggest using "s. Make it so the second argument is everything from the first quote to the second. Like this:
say "hello world" command
say - argument one
"hello world" - arg2
command - arg3
Hope this helps :3