Admin kick script doesn't work

So for a while I’ve been writing an admin panel for general purpose use on my games, and I encountered an issue that is happening when I try to use the “kick” feature in my panel. Here are the scripts:

Local script, inside of a textbox.

local plr = game.Players.LocalPlayer

script.Parent.FocusLost:Connect(function(enterPressed, inputObject)
	local players = game.Players:GetChildren()
	if enterPressed then
		local player = script.Parent.Text
		for i,v in pairs(players) do
			if v.Name == player then
				game.ReplicatedStorage.ccKickEvent:FireServer(plr,player)
				print("Player has successfully been found!")
				script.Parent.Text = "Player has successfully been found!"
				wait(2.5)
				script.Parent.Text = "Enter player name to kick!"
			end
			
			if v.Name ~= player then
				print("Player hasn't been!")
				script.Parent.Text = "Player hasn't been found!"
				wait(2.5)
				script.Parent.Text = "Enter player name to kick!"
			end
		end
	end
	
end)

script.Parent.Focused:Connect(function()
	local name = script.Parent.Text
end)

Server script inside of ServerScriptService

game.ReplicatedStorage.ccKickEvent.OnServerEvent:Connect(function(plr,player)
	player:Kick(plr.Name.." has chosen you, "..player.Name.." to be kicked!")
end)

What’s happening is that when I try to kick another person, it just kicks me for no reason. When I try to kick myself, it works perfectly fine.


Any help is appreciated!

You don’t have to send the LocalPlayer to the server, it’s automatically defined.

game.ReplicatedStorage.ccKickEvent:FireServer(player)

1 Like

your passing “player” as a string object. It has to be a player object so do:

game.Players[player]:Kick(plr.Name.." has chosen you, "..player.Name.." to be kicked!")

1 Like

Hes sending the player to kick onto the server not the localplayer

He’s sending the local player when he’s firing the server.

game.ReplicatedStorage.ccKickEvent:FireServer(plr,player)

should be

game.ReplicatedStorage.ccKickEvent:FireServer(player)

because player is the “goal” player. plr is defined as LocalPlayer at the top of the script.

oh bruh I skimmed over it and didn’t see that lol

Edit: Please help me my brain is slowly disintegrating from being careless :open_mouth:

2 Likes

I tried remove the “plr” in the calling of the remote event, and I got an error:

image

Any ideas as to why this is happening?

Updated script:

local plr = game.Players.LocalPlayer

script.Parent.FocusLost:Connect(function(enterPressed, inputObject)
	local players = game.Players:GetChildren()
	if enterPressed then
		local player = script.Parent.Text
		for i,v in pairs(players) do
			if v.Name == player then
				game.ReplicatedStorage.ccKickEvent:FireServer(player)
				print("Player has successfully been found!")
				script.Parent.Text = "Player has successfully been found!"
				wait(2.5)
				script.Parent.Text = "Enter player name to kick!"
			end
			
			if v.Name ~= player then
				print("Player hasn't been!")
				script.Parent.Text = "Player hasn't been found!"
				wait(2.5)
				script.Parent.Text = "Enter player name to kick!"
			end
		end
	end
	
end)

script.Parent.Focused:Connect(function()
	local name = script.Parent.Text
end)

Hmm, looks like it’s coming from your server script. Could you send your full one?

1 Like
game.Players.PlayerAdded:Connect(function(plr)
	workspace.ChildAdded:Connect(function(child)
		for i,v in pairs(child:GetChildren()) do
			if v.Name == "Humanoid" and v:IsA("Humanoid") then
				if plr.UserId == 786513213 or plr.UserId == 168464656 then
					game.ReplicatedStorage.ccEvent:FireClient(plr)
				end
			end
		end
	end)
end)	
		--if plr.UserId == 786513213 or plr.UserId == 168464656 then
		--	game.ReplicatedStorage.ccEvent:FireClient(plr)
		--end

game.ReplicatedStorage.ccKickEvent.OnServerEvent:Connect(function(plr,player)
	player:Kick(plr.Name.." has chosen you, "..player.Name.." to be kicked!")
end)

game.ReplicatedStorage.ccKillEvent.OnServerEvent:Connect(function(player)
	player.Character.Humanoid.Health = 0
	
end)

game.ReplicatedStorage.ccFreezeEvent.OnServerEvent:Connect(function(plr,player)
	player.Character.HumanoidRootPart.Anchored = true
end)

game.ReplicatedStorage.ccHealthEvent.OnServerEvent:Connect(function(plr,hp)
	print(hp)
	plr.Character.Humanoid.MaxHealth += hp
	plr.Character.Humanoid.Health += hp	
end) 

Most of it is jut reused code from the original kick script, so I was planning on fixing just the kick script so I could re-do the rest of the scripts with my new knowledge.

Ah, I see.

Try this. You would want to send the player object to the server, not the name:

game.ReplicatedStorage.ccKickEvent:FireServer(v)
1 Like

It works now, but I need to test the script in multiplayer, not just in studio. Thank you.

EDIT: It kind of works, when I insert someone’s name into the text box, it says “Player hasn’t been found!” but then, 2.5 seconds later, it says “Player has been successfully found!” and kicks the person, any ideas as to why this is happening?

EDIT2: Yeah I’m going for the lazy option of doing nothing if the player types in the wrong name lol.

1 Like