Help with admin script

I have created a TextBox for admin and have this LocalScript in the client side code. “if string.lower(string.sub(Text, 1, 6)) == “:kick” then
local syntax = string.sub(Text, 7)
if string.lower(syntax) == “me” then
Kick:FireServer(LocalPlayer, “You’re not welcome here at the moment.”)” and for the remote event Kick its "function kickPlayer(player, message)
player:Kick(message)
end

game:GetService(“ReplicatedStorage”).Kick.OnServerEvent:Connect(kickPlayer)" but this code does not work. I’ve tried fixing it with lots of methods and even asked an ai but it didn’t work. DevForum is my last choice.

1 Like

Could you format your script in a code block?

```lua

```
1 Like

Yeah

RemoteEvent serverside script: ```
function kickPlayer(player, message)
player:Kick(message)
end

game:GetService(“ReplicatedStorage”).Kick.OnServerEvent:Connect(kickPlayer)

And the Admin TextBox LocalScript: ```
if string.lower(string.sub(Text, 1, 6)) == ":kick" then
			local syntax = string.sub(Text, 7)
			if string.lower(syntax) == "me" then
				Kick:FireServer(LocalPlayer, "You're not welcome here at the moment.")

The Kick event and LocalPlayer are variables but I think that might be obvious if not then yeah.

1 Like

You do not need to pass the player as an argument, it is already a default.
So, just remove LocalPlayer argument…

Kick:FireServer("You're not welcome here at the moment.")

Ooh, yeah, if you are trying to pass the target player and not just the local player, add a second parameter to your server script code:

function kickPlayer(player, targetplayer, message)
    targetplayer:Kick(message)
end

game:GetService(“ReplicatedStorage”).Kick.OnServerEvent:Connect(kickPlayer)
1 Like

I did that and it didn’t work. It seems that all that happens is that when I do “:kick me” nothing happens but when I just do “:kick” it kicks me so I’m very confused. The full code is

local Players = game:GetService("Players")
local Kick = game:GetService("ReplicatedStorage"):WaitForChild("Kick")
local Admins = {
	JonsStuffMC = true,
	FireBoySosa = true
}
local LocalPlayer = Players.LocalPlayer
game:GetService("UserInputService").InputBegan:Connect(function(player)
	if Admins[LocalPlayer.Name] and player.KeyCode == Enum.KeyCode.BackSlash then
		wait()
		script.Parent.Enabled = true
		script.Parent:WaitForChild("Frame"):WaitForChild("TextBox"):CaptureFocus()
	end
end)
script.Parent:WaitForChild("TextButton").MouseButton1Down:Connect(function()
	script.Parent.Enabled = false
end)
script.Parent:WaitForChild("Frame"):WaitForChild("TextBox").FocusLost:Connect(function()
	local Text = script.Parent:WaitForChild("Frame"):WaitForChild("TextBox").Text
	if Admins[LocalPlayer.Name] then
		if string.lower(string.sub(Text, 1, 6)) == ":kick" then
			local syntax = string.sub(Text, 7)
			if string.lower(syntax) == "me" then
				Kick:FireServer("You're not welcome here at the moment.")
			elseif string.lower(syntax) == "all" then
				for _, player in pairs(Players:GetChildren()) do
					Kick:FireServer(player, "You're not welcome here at the moment.")
				end
			elseif string.lower(syntax) == "other" or string.lower(syntax) == "others" then
				for _, players in pairs(Players:GetChildren()) do
					if players ~= LocalPlayer then
						Kick:FireServer(players, "TestReason")
					end
				end
			else
				for _, player in pairs(Players:GetChildren()) do
					if string.lower(syntax) == string.lower(string.sub(player.Name, 1, string.len(syntax))) then
						Kick:FireServer(player, "TestReason")
					end
				end
			end
		end
	end
end)

The backslash enables the GUI for admin and the other syntax code is for testing.

1 Like

Are you sure that this statement work?
Check the last part of my last response…

1 Like

Yeah, I haven’t coded lua in a while and I asked an AI if it was correct and it said it was. I also know because I remember coding this in 2019 but I lost the file and quit game development

1 Like

I don’t know what is the exact part that isn’t working. Try to trace the issue using some prints on the server script and local one.

1 Like

Alright, thanks for the help though!

1 Like

wait am I being stupid (it very much could be) or do u need to use the command like “:kickme” rather then “:kick me”?

Hmmm… try changing it to string.sub(Text,1,5) and syntax = string.sub(Text,6)

Also try printing the content of syntax

1 Like

Everyone im sorry it turns out I forgot to add a space after “:kick” so it should have been ":kick " so sorry

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.