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

how can i make my kick have the player and a optional reason?

Asked by 4 years ago

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:

01function Run(args)
02    script.Parent.Parent.exe.SE:FireServer("",args)
03end
04 
05game: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)
View all 36 lines...

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.

0
You can use string.split(STRINGTOSPLIT, " "), string.split() returns as a table, so you can loop through it. nekosiwifi 398 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

string.split(str, match) is a function that, like it describes returns a table that is split at a certain match, example:

1local a = "aioskodaoik oasdojs"
2local b = string.split("a", " ")
3print(b[1]) -- will print aioskodaoik

In your case, use this:

01function Run(args)
02    script.Parent.Parent.exe.SE:FireServer("",args)
03end
04 
05game: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)
View all 36 lines...
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Ive got a working one thx to widesteal, if you wanna check my version out here it is:

01function Run(args)
02    script.Parent.Parent.exe.SE:FireServer("",args)
03end
04 
05game: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 = {}
View all 41 lines...

I use a table to put the spaces back together so the words are seperated

0
idk why i cant accept my own answer anymore so ill just accept wide's mahid786 41 — 4y

Answer this question