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.
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.