So I am detecting when a player chats with in a local script.
Player.Chatted:connect(function(Message) end)
but how can I pick out certain things of that message and define them as a variable? I've tried things like:
Player.Chatted:connect(function(Message) if Message == "Hello " then --code end)
but how do I get what's after "Hello ", so if the player says "Hello World" I can continue, but if they say "Hello foo" something else will happen, but mainly defining the 'extra' (world, bananas) as its own variable so like;
Args = string.sub() --?
Not that good with string. - any help would be appreciated.
Match it
If the pattern fits.
If you want to start getting into more variadic stuff, you want to look at string pattern matching. In your case, you should be good to just collect anything that isn't whitespace into a table:
local t = {}; spoken:gsub('%S+', function(c) t[#t+1] = c end);
What this does is:
t
%S+
do:
t
The pattern %S+
is formed of:
%S
which matches anything which is not a whitespace (%s
matches anything which is a whitespace)+
matches 1 or more occurrences of the preceding pattern.