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:
function Run(args) script.Parent.Parent.exe.SE:FireServer("",args) end game:GetService("UserInputService").InputBegan:Connect(function(e,gpe) if e.UserInputType == Enum.UserInputType.Keyboard then if e.KeyCode == Enum.KeyCode.Return then local text = script.Parent.Text local txt = script.Parent if string.find(text:sub(1, 4), "kick") and string.find(text:sub(6, #text), ".+") then txt.Text = '' local user = text:sub(6, #text) local reason = "No Reason Given." if string.find(text:sub((6 + #user), #text), ".+") then reason = text:sub((6 + #user), #text) end if user:lower() == "others" then for _,plrs in pairs(game.Players:GetChildren()) do if plrs.Name ~= game.Players.LocalPlayer.Name then Run("game.Players." .. plrs.Name ..":Kick('" .. reason .. "')") end end elseif user:lower() == "all" then for _,plrs in pairs(game.Players:GetChildren()) do Run("game.Players." .. plrs.Name ..":Kick('" .. reason .. "')") end end for _,plr in pairs(game.Players:GetChildren()) do if (plr.Name:lower():sub(1,#user) == user) then Run("game.Players." .. plr.Name ..":Kick('" .. reason .. "')") end end end end end end)
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:
local a = "aioskodaoik oasdojs" local b = string.split("a", " ") print(b[1]) -- will print aioskodaoik
In your case, use this:
function Run(args) script.Parent.Parent.exe.SE:FireServer("",args) end game:GetService("UserInputService").InputBegan:Connect(function(e,gpe) if e.UserInputType == Enum.UserInputType.Keyboard then if e.KeyCode == Enum.KeyCode.Return then local text = script.Parent.Text local txt = script.Parent if string.find(text:sub(1, 4), "kick") and string.find(text:sub(6, #text), ".+") then txt.Text = '' local user = text:sub(6, #text) local reason = string.split(text, " ")[3] if string.find(text:sub((6 + #user), #text), ".+") then reason = text:sub((6 + #user), #text) end if user:lower() == "others" then for _,plrs in pairs(game.Players:GetChildren()) do if plrs.Name ~= game.Players.LocalPlayer.Name then Run("game.Players." .. plrs.Name ..":Kick('" .. reason .. "')") end end elseif user:lower() == "all" then for _,plrs in pairs(game.Players:GetChildren()) do Run("game.Players." .. plrs.Name ..":Kick('" .. reason .. "')") end end for _,plr in pairs(game.Players:GetChildren()) do if (plr.Name:lower():sub(1,#user) == user) then Run("game.Players." .. plr.Name ..":Kick('" .. reason .. "')") end end end end end end)
Ive got a working one thx to widesteal, if you wanna check my version out here it is:
function Run(args) script.Parent.Parent.exe.SE:FireServer("",args) end game:GetService("UserInputService").InputBegan:Connect(function(e,gpe) if e.UserInputType == Enum.UserInputType.Keyboard then if e.KeyCode == Enum.KeyCode.Return then local text = script.Parent.Text local txt = script.Parent if string.find(text:sub(1, 4), "kick") and string.split(text, " ")[2] then txt.Text = '' local user = string.split(text, " ")[2] local reason = "No Reason Given." if string.split(text, " ")[3] then local rTable = {} reason = "" for i = 3, #string.split(text, " ") do table.insert(rTable, (#rTable + 1), string.split(text, " ")[i]) end reason = table.concat(rTable, " ") end if user:lower() == "others" then for _,plrs in pairs(game.Players:GetChildren()) do if plrs.Name ~= game.Players.LocalPlayer.Name then Run("game.Players." .. plrs.Name ..":Kick('" .. reason .. "')") end end elseif user:lower() == "all" then for _,plrs in pairs(game.Players:GetChildren()) do Run("game.Players." .. plrs.Name ..":Kick('" .. reason .. "')") end end for _,plr in pairs(game.Players:GetChildren()) do if (plr.Name:lower():sub(1,#user) == user) then Run("game.Players." .. plr.Name ..":Kick('" .. reason .. "')") end end end end end end)
I use a table to put the spaces back together so the words are seperated