Kick GUI not working

I am trying to make a GUI for an admin to kick someone from a server. When I click the button on the GUI it does not kick other players even when pressing on their name all it does is kick the admin. How would I fix this? The script is bigger but I am shortening it to where the problem is.

Local Script
for _,target in pairs(players:GetPlayers()) do
local new = template:Clone()
new.Parent = ScrollingFrame
new.Text = target.Name

			new.MouseButton1Click:Connect(function()
				KickPlayerEvent:FireServer(target)
			end)
		end

Server Script
local KickPlayerEvent = game.ReplicatedStorage:WaitForChild(“KickPlayer”)

KickPlayerEvent.OnServerEvent:Connect(function(target, plr)

target:Kick("You have been kicked from the server.")

print(plr.Name .. ", Has been kicked from the server.")

end)
3 Likes

On your server script you are putting the client who fired the event (target) before the victim specified in the local script:

KickPlayerEvent.OnServerEvent:Connect(function(admin, target)

target:Kick("You have been kicked from the server.")

print(target.Name .. ", Has been kicked from the server.")

end)

The above code should work on the server.

.

Additionally, I can see you aren’t setting the position of your buttons on the local script; so you might want to do that.

5 Likes

In addition to what @0e_l has stated. I noticed that your server script has no form of validation to prevent exploiters from kicking players. You should add a line to check the user that that fired the event.

6 Likes

Yes, that does seem like something I would need to work on since I don’t want exploiters running around kicking people.

1 Like

Yes, a simple if statement will be enough.

1 Like

If you’re not familiar with this informative thread about exploiters, then I recommend you read this: Exploiting Explained

3 Likes

Here’s a follow-up post containing everything you need!

I decided to go ahead and write this to give you a rough idea of what you should do:
Server

local KickPlayerEvent = Instance.new('RemoteEvent') -- You'll want to change this.

local AdminList = {123456, "Builderman"} -- Put in User IDs or Names here!

-- Let's make a function to simplify the process
function isAdmin(Player)
	for _,item in pairs(AdminList) do
		
		if type(item) == "number" then -- If it's a number, it MUST be a User Id!
			if Player.UserId == item then -- If it's the player's User ID...
				return true
			end
		elseif type(item) == "string" then -- It would be a username
			if Player.Name:lower() == item:lower() then -- If it's the player's name... (We've made it in lowercase so that way you don't have to worry about capitalisation in your admin list)
				return true
			end
		end
		
	end
	
	-- If all other checks have failed..
	return false -- The player is not an admin.
end

KickPlayerEvent.OnServerEvent:Connect(function(admin, target)
	
	if isAdmin(admin) then
		
		target:Kick('You have been kicked from the server.')
		print(target.Name.." has been kicked from the server by ".. admin.Name)
		
	else
		-- They must be an exploiter!
		admin:Kick('Exploiting: Fired KickPlayerEvent when not admin')
	end
	
end)

Client

local ScrollingFrame = Instance.new('ScrollingFrame')
local template = Instance.new('TextButton')
local KickPlayerEvent = Instance.new('RemoteEvent')
-- You might want to change the two above!

local players = game:GetService('Players') -- You should use GetService instead of game.Players

-- You might want to include some client check to ensure the player is an admin before giving them the option to do this.
	
-- We'll make it a function so it can be repeated over and over
function renderPlayersToKick()
	ScrollingFrame:ClearAllChildren() -- Prevent duplicates
	
	for i,user in pairs(players:GetPlayers()) do
		
		local new = template:Clone()
		new.Parent = ScrollingFrame
		new.Text = user.Name
		
		-- Now let's set the position of the button
		if i == 1 then
			new.Position = UDim2.new(0,0,0, 0) -- We don't want it to start at 50, we want it to start at one.
		else
			new.Position = UDim2.new(0,0,0, (i * 50)) -- We'll assume the Y is '50', the default for TextButtons.
		end
		
		new.MouseButton1Click:Connect(function()
			KickPlayerEvent:FireServer(user)
		end)
		
	end
end

renderPlayersToKick() -- Generate the list

-- Regenerate the list if a player joins or leaves
game.Players.PlayerAdded:Connect(renderPlayersToKick)
game.Players.PlayerRemoving:Connect(renderPlayersToKick)

Also, as @uJordy said, the Exploiting Explained thread is useful if you’re not familiar with it.

5 Likes

@MasonTheCreeperYT3 You should mark the post which helps as the solution, this way the user whom helped you gets credit and others will see the :white_check_mark: in the thread list (which can help others with the same problem)

6 Likes

Thanks for helping I just did that :smile: