Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Multiple Arguments in Chat?

For my game I'm trying to make a chat command to give guns, such as "GLOCK 18". I want to fire a remote event to give the person the gun. However, I want the gun to be said as two different strings so "GLOCK" "18". So when a player types: :givetool GLOCK 18 it will fire Network.Storage.Weapon.[var][var2]. Var being GLOCK and var2 being 18. But it won't work.

Code:

if cmd == "givetool" then
local var = string.sub(msg,space+1)
local var2 = string.sub(var,space+1)
				

local string_1 = "Tool";
local userdata_1 = game:GetService("ReplicatedStorage").Network.Storage.Weapon.[var][var2];
local Target = game:GetService("ReplicatedStorage").Network.AssignEntity;
Target:FireServer(string_1, userdata_1);


end

Edit:

I'm also afraid that...

local var = string.sub(msg,space+1)
local var2 = string.sub(var,space+1)

...wont work either.

11 comments

0

um you write [var]][var2]

0

lol maybe that typo is the problem

0

And yes I know it's some stupid syntax mistake

0

I didn't mean to add the ] in my code however without it still doesn't work.

0

have you tried Weapon..var""..var2 ?

0

no but I will try

0

still didnt work

0

can i see the script with u using it?

0

wait i got a good idea, write local Weapn = var..""..var2 then write Weapon.Weapn

0

SMART

0

didnt work either

1 answer

✓ Accepted answer

Use string.split(YOUR_STRING_HERE, " ")

table string.split ( string s, string separator = , )

If used on ":givetool GLOCK 18", it will split the string into a table:

local splitString = string.split(":givetool GLOCK 18", " ")
for _,str in pairs(splitString) do
	print(str)
end

-- Output:
-- :givetool
-- GLOCK
-- 18

The first index of the table would be the command, everything after would be considered an argument.

This discussion is preserved as it was. New answers, comments, and votes are closed.