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

My kick script does not kick a player?

So I am making an admin panel and need help. This script doesn't even kick the player that the player wants to kick. How can I fix this? It's a script not a local script

script.Parent.MouseButton1Click:Connect(function()
	local plrname = script.Parent.Parent.Title.Text
	local p = game.Players:FindFirstChild(plrname)
	
	if p then
		p:Kick("You have been kicked.")
	end
end)

1 comment

0

If its a script trying to get a mousebutton click it probably wont work try putting this in a local script and then setting a remote event to fire a message to the server to kick the player, hopefully this helps!

3 answers

i guess thats a local script, local scripts cant kick other players because they dont replicate anything to the server, you would need a remote event to tell the server what to do and in the server script, kick the player

1 comment

0

It's not a local script

What is script.Parent.Parent.Title? If it's a TextBox then the issue would be that when you're typing text into a textbox, you're typing it from your client and therefore the server can't read the text you've just inputted.

To fix this, I'd suggest using a RemoteEvent and passing the Text from the client to the server, and to also check if the player that fired the RemoteEvent is an admin to avoid exploiters abusing this.

Local Script

-- You can change the RemoteEvent's name to whatever you like.
local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")

script.Parent.MouseButton1Click:Connect(function()
	local plrname = script.Parent.Parent.Title.Text

	RemoteEvent:FireServer(plrname)
end)

Server Script

-- You can change the RemoteEvent's name to whatever you like.
local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")

RemoteEvent.OnServerEvent:Connect(function(PlayerFired, PlayerToKick)
	
	-- Check if `PlayerFired` is an admin here to avoid exploiters from abusing this.

	if PlayerToKick then
		if game.Players:FindFirstChild(PlayerToKick) then
			game.Players[PlayerToKick]:Kick("You have been kicked")
		end
	end
end)

2 comments

0

Oh now I know why I was defining the wrong object lol

0

Still doesn't work neither does it print an output

I think xInfinityBear's code doesn't work for you because you need the full name of a player ( capital letters, underscore, etc ).

You should do this instead:

Local Script:

local RS = game:GetService("ReplicatedStorage")
local RemoteEvent = RS:WaitForChild("RemoteEvent")

local TextBox =  -- Define your text box

script.Parent.MouseButton1Click:Connect(function()
	local player = tostring(TextBox.Text)
	
	if player ~= nil then
		RemoteEvent:FireServer(player)
	end
end)

Server Script:

local RS = game:GetService("ReplicatedStorage")
local RemoteEvent = RS:WaitForChild("RemoteEvent")

RemoteEvent.OnServerEvent:Connect(function(playerWhoFired, playerToKick)
	-- Check if the player who fired is an admin or not

	for _, player in pairs(game.Players:GetChildren()) do
		if player.Name:lower() == playerToKick:lower() then
			if player:IsDescendantOf(game) then
				player:Kick("You are kicked.")
			end
		end
	end
end)

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