I want my kick command to be able to kick the said player and at the same time have an option to be able to say a reason as well but, I cant seem to be able to get the player and the reason separately. Here is my script:
01 | function Run(args) |
02 | script.Parent.Parent.exe.SE:FireServer( "" ,args) |
03 | end |
04 |
05 | game:GetService( "UserInputService" ).InputBegan:Connect( function (e,gpe) |
06 | if e.UserInputType = = Enum.UserInputType.Keyboard then |
07 | if e.KeyCode = = Enum.KeyCode.Return then |
08 | local text = script.Parent.Text |
09 | local txt = script.Parent |
10 | if string.find(text:sub( 1 , 4 ), "kick" ) and string.find(text:sub( 6 , #text), ".+" ) then |
11 | txt.Text = '' |
12 | local user = text:sub( 6 , #text) |
13 | local reason = "No Reason Given." |
14 | if string.find(text:sub(( 6 + #user), #text), ".+" ) then |
15 | reason = text:sub(( 6 + #user), #text) |
i have used prints in parts of the script and they have been removed, the result I'm getting is the user and reason together when I try to print local user
. Please someone help me because I don't know what to do at this point.
string.split(str, match)
is a function that, like it describes returns a table that is split at a certain match, example:
1 | local a = "aioskodaoik oasdojs" |
2 | local b = string.split( "a" , " " ) |
3 | print (b [ 1 ] ) -- will print aioskodaoik |
In your case, use this:
01 | function Run(args) |
02 | script.Parent.Parent.exe.SE:FireServer( "" ,args) |
03 | end |
04 |
05 | game:GetService( "UserInputService" ).InputBegan:Connect( function (e,gpe) |
06 | if e.UserInputType = = Enum.UserInputType.Keyboard then |
07 | if e.KeyCode = = Enum.KeyCode.Return then |
08 | local text = script.Parent.Text |
09 | local txt = script.Parent |
10 | if string.find(text:sub( 1 , 4 ), "kick" ) and string.find(text:sub( 6 , #text), ".+" ) then |
11 | txt.Text = '' |
12 | local user = text:sub( 6 , #text) |
13 | local reason = string.split(text, " " ) [ 3 ] |
14 | if string.find(text:sub(( 6 + #user), #text), ".+" ) then |
15 | reason = text:sub(( 6 + #user), #text) |
Ive got a working one thx to widesteal, if you wanna check my version out here it is:
01 | function Run(args) |
02 | script.Parent.Parent.exe.SE:FireServer( "" ,args) |
03 | end |
04 |
05 | game:GetService( "UserInputService" ).InputBegan:Connect( function (e,gpe) |
06 | if e.UserInputType = = Enum.UserInputType.Keyboard then |
07 | if e.KeyCode = = Enum.KeyCode.Return then |
08 | local text = script.Parent.Text |
09 | local txt = script.Parent |
10 | if string.find(text:sub( 1 , 4 ), "kick" ) and string.split(text, " " ) [ 2 ] then |
11 | txt.Text = '' |
12 | local user = string.split(text, " " ) [ 2 ] |
13 | local reason = "No Reason Given." |
14 | if string.split(text, " " ) [ 3 ] then |
15 | local rTable = { } |
I use a table to put the spaces back together so the words are seperated