Kick GUI Not Working

Hello! So, I’m creating a kick GUI but it doesn’t seem to work. Any help?

LocalScript

local KickUser = script.Parent.KickBox.Text
local KickText = script.Parent.KickReason.Text
local KickReason = ''
local plr = game.Players.LocalPlayer

--//Kick System

script.Parent.KickButton.Activated:Connect(function()
	if KickText == '' then
		KickReason = '\n\nReason: Reason UnSpecified\nKicked By: '..plr.Name
	else
			KickReason = '\n\nYou Were Kicked From The Game!\nReason: '..KickText..'\nKicked By: '..plr.Name
	end
	if game.Players:FindFirstChild(KickUser) then
	script.Parent.Kick:FireServer(KickUser, KickReason)
	else
		script.Parent.KickBox.Text = 'Invalid Player!'
	end
end)

Remote Event Script

script.Parent.OnServerEvent:Connect(function(p, user, reason)
		game.Players(user):Kick(reason)
end)
1 Like

Try changing this line:

game.Players(user):Kick(reason)

To this:

game.Players[user]:Kick(reason)

(Assuming “user” is a string)

Also, I would add better exploit protection to your code. Currently, an exploiter could just fire the event and kick anyone they wanted.

game.Players(user) would be the syntax to call a function called Players from the game object. To actually get the user, you need to use [square brackets] not (parentheses), so you would do game.Players[user]:Kick(reason).

1 Like

If none of the other replies work, I rewrote it for you!

Localscript :
local KickUser

local KickText

local KickReason = ‘’

local plr = game.Players.LocalPlayer

script.Parent.KickButton.Activated:Connect(function()

KickUser = script.Parent.plr.Text

KickText = script.Parent.reason.Text

if KickText == ‘’ then

KickReason = '\n\nReason: Reason UnSpecified\nKicked By: '…plr.Name

else

KickReason = '\n\nYou Were Kicked From The Game!\nReason: ‘…KickText…’\nKicked By: '…plr.Name

end

game:GetService(“ReplicatedStorage”).Kick:FireServer(KickUser, KickReason)

end)

ServerScript :
local plr
game:GetService(“ReplicatedStorage”).Kick.OnServerEvent:Connect(function(p, user, reason)
print(user)
for _,v in pairs(game.Players:GetPlayers()) do
if v.Name == user then
plr = v
else
print(“Player not found!”)
end
end
plr:Kick(reason)
end)

I formatted the code so it is easier to read and understand.


LocalScript:

local KickUser
local KickText
local KickReason = ''

local plr = game.Players.LocalPlayer

script.Parent.KickButton.Activated:Connect(function()
	KickUser = script.Parent.plr.Text
	KickText = script.Parent.reason.Text
	
	if KickText == '' then
		KickReason = '\n\nReason: Reason UnSpecified\nKicked By: ' .. plr.Name
	else
		KickReason = '\n\nYou Were Kicked From The Game!\nReason: ' .. KickText .. '\nKicked By: ' .. plr.Name
	end
	
	game:GetService("ReplicatedStorage").Kick:FireServer(KickUser, KickReason)
end)

ServerScript:

game:GetService("ReplicatedStorage").Kick.OnServerEvent:Connect(function(p, user, reason)
	for _, player in pairs(game.Players:GetPlayers()) do
		if player.Name == user then
			player:Kick(reason)
		else
			print("Player not found!")
		end
	end
end)

(I also changed up the ServerScript a bit)

1 Like

thanks lol, I just suck at this

1 Like

This code still has a flaw that was mentioned by @SS4PPHIRE. You should consider adding an admin table on the server and compare that to the player UserId who sent the RemoteEvent. It would be better if you just put more of this code on the server instead of leaving the server doing the simple tasks.

You are right, but this is something @Aiden_12114 needs to add themselves.

Well it is in a module script so gl to them lol

It ended up saying player not found :confused:

1 Like

Screen Shot 2020-05-10 at 11.45.41 am

1 Like

The problem isn’t where the script is located on the server, it is that any player can fire the RemoteEvent to kick another player because you aren’t checking whether the player that fired the RemoteEvent is an admin / has permission to do so. This leaves it open for any exploiter to kick anyone in the game because you haven’t stopped unauthorised players from kicking.

1 Like

It’s located inside the GUI. Idk if it will work tho? :thinking:

1 Like

Screen Shot 2020-05-10 at 11.47.52 am

1 Like

The script works but it’s just the Player Checking script. It should work but it won’t :man_shrugging:

1 Like

They can still fire it even if it’s in a GUI, and they are able to find out the parameters using a RemoteSpy or something. All they would have to do to kick everyone from the server is something like this:

for i,v in pairs(game.Players:GetPlayers()) do
	remote:FireServer(v.Name, "get kicked noob")
end
4 Likes

Luckily, adding fixes to prevent this is extremely simple. You could just add a :GetRankInGroup() function if you wanted to keep it simple, or have a permissions table or something.

game:GetService("ReplicatedStorage").Kick.OnServerEvent:Connect(function(p, user, reason)
	if p:GetRankInGroup(urgroupid) >= rankid then
		for _, player in pairs(game.Players:GetPlayers()) do
			if player.Name == user then
				player:Kick(reason)
			else
				print("Player not found!")
			end
		end
	else
		p:Kick("exploiter")
	end
end)

Edit: The only thing you would want to be careful about is that you dont give the UI to any staff who aren’t allowed to use it to avoid kicking people for exploiting when they just don’t have the proper permissions to do it.

1 Like

It’s an OS System found in #resources:community-resources So it’s the Dev’s choice for who gains access. (AdminSystems Btw)

1 Like

something like this

  local banList ={12213, 24124, 124124} -- these are UserIds of banned people
  local players = game:GetService("Players")
  
  players.PlayerAdded:Connect(function(player)
          if table.find(banList, player.UserId) then 
          player:Kick(reason)
  end)

Why did you use remote events? You can just do this on PlayerAdded and see whether a player’s UserId is in the array, if it is then kick the player

2 Likes