Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Multiple Arguments in Chat?

Asked by 3 years ago
Edited 3 years ago

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.

0
um you write [var]][var2] TheUltimateTNTFriend 109 — 3y
0
lol maybe that typo is the problem TheUltimateTNTFriend 109 — 3y
0
And yes I know it's some stupid syntax mistake ScriptedWrath 16 — 3y
0
I didn't mean to add the ] in my code however without it still doesn't work. ScriptedWrath 16 — 3y
View all comments (7 more)
0
have you tried Weapon..var""..var2 ? TheUltimateTNTFriend 109 — 3y
0
no but I will try ScriptedWrath 16 — 3y
0
still didnt work ScriptedWrath 16 — 3y
0
can i see the script with u using it? TheUltimateTNTFriend 109 — 3y
0
wait i got a good idea, write local Weapn = var..""..var2 then write Weapon.Weapn TheUltimateTNTFriend 109 — 3y
0
SMART ScriptedWrath 16 — 3y
0
didnt work either ScriptedWrath 16 — 3y

1 answer

Log in to vote
3
Answered by
appxritixn 2235 Moderation Voter Community Moderator
3 years ago

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.

Ad

Answer this question