Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

My Kick GUI isn't kicking players like it is supposed to, Please help if you can :) (?)

Hello, I've been programming a simple kick GUI, so when you click 'Kick' it'll get the players name from a text box in the GUI and the reason of the kick, but it doesn't kick me when I test it.

The script is a Local Script not server side.

Here it is:

-- // Script Written by: DevCadenator
-- // Script title: Basic Kick Script, 29/10/2018 (DD/MM/YY)
-- // Notice: None

script.Parent.MouseButton1Click:Connect(function()-- When the player clicks on the button it will run the function below.
	-- Varibles --
	local player = game.Players:FindFirstChild(script.Parent.Parent.KickValue.Text) -- The player to kick.
	local reason = script.Parent.Parent.KickValue2.Text -- The reason that the Admin entered.
	-- Primary Script --
	if player == nil then -- Checks if the player doesn't exist.
		warn("Player - " .. script.Parent.Parent.KickValue.Text " does not exist!") -- Sends a warning to the console that the player doesn't exist.
	else -- If the player exists then the code will continue below, else it will stop.
		if reason == "Reason" then -- Checks if the Admin didn't write a reason.
			print("No reason provided for " .. player.Name .. " kick.") -- Prints to console saying that there is no reason provided for the kick.
		player:Kick("No reason provided") -- Kicks the player with the text saying "No reason provided"
		else -- If the reason isn't blank then it will continue to run the code below.
			print("Checking permission level to kick " .. player.Name .. " for " .. reason) -- Prints to the console that administrator.
			wait(0.1) -- Puts a wait time in-between when a string is printed to console and when the player is kicked.
			player:Kick(reason) -- Kicks the player for the reason.
			print(player.Name .. " has been kicked for: " .. reason) -- Prints to console that a player has been kicked and for what reason.
	-- End of Script --
		end
	end
end) -- This will end the function. 
	
	
	
--- Script created for - The Queens Hotel ---

	

Any help would be greatly appreciated.

Caden

3 comments

0

Could you get rid of all those comments LOL

0

^ comments are helpful wym

0

But over-commenting code is a code smell

1 answer

ServerSide

The Kick action is available only through the Server. So to fix this use Remotes

Handle all the GUI on the client side, and then have it fire a remote to signal the server to kick the player. As an example:

LOCAL

script.Parent.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.kickEvent:FireServer(KickValue.Text, KickValue2.Text)
end)

SERVER

game.ReplicatedStorage.kickEvent.OnServerEvent:Connect(function(plr, KickValue, KickValue2)
	game.Players:FindFirstChild(KickValue):Kick(KickValue2)
end)

Keep in mind this is just example code, I can not provide you with an entire script. If you need help with anything, just comment below this.

8 comments

0

I'm confused where to put things,

0

The Kick method can be done from the client, but clients can only kick themselves.

0

Oh.

0

you really don't want to let any player kick anyone through a remote event

0

Oh, It's for an admin pannel lol.

0

I've done what you said, but it still isn't working.

0

I'm not getting any errors in studio though.

0

Just taking a quick look, this could looks like it'd work. Just a warning though. You MUST verify SERVER SIDE that this player should be able to kick other players if you don't want exploiters to kick random people.

This discussion is preserved as it was. New answers, comments, and votes are closed.