Not giving a reason when kicked

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? For it to show the reason when they get kicked.

  2. What is the issue? Doesn’t show the reason

  3. What solutions have you tried so far? No I did not find anything I tried messing with it but nothing changed.

local Players = game:GetService("Players")
local Remote = game.ReplicatedStorage.KICK

local admins = {528285072}

Remote.OnServerEvent:Connect(function(player1, targetUsername, reason)
	local reason = game.StarterGui.AdminPanel.KICKCMD.Reason == reason
	if not table.find(admins, player1.UserId) then return end
	local player2 = Players:FindFirstChild(targetUsername)
	if not player2 then return end 
	player2:Kick("Kicked for", reason)
end)

image

What’s the reason for having game.StarterGui.AdminPanel.KICKCMD.Reason == reason? This makes reason a boolean.

Try this:

local Remote = game.ReplicatedStorage.KICK

local admins = {528285072}

Remote.OnServerEvent:Connect(function(player1, targetUsername, reason)
	local reason = game.StarterGui.AdminPanel.KICKCMD.Reason
	if not table.find(admins, player1.UserId) then return end
	local player2 = Players:FindFirstChild(targetUsername)
	if not player2 then return end 
	player2:Kick("Kicked for".. reason)
end)```
2 Likes

Not quite sure what I was thinking putting that there.

1 Like

Cannot do it I tried that before.

1 Like

Two things that you can’t do there.

  1. Any changes a player makes to a gui object does not replicate to the server.
  2. The player’s gui stuff is located in their PlayerGui, not the game’s StarterGui.
local reason = game.Players.LocalPlayer.PlayerGui.AdminPanel.KICKCMD.Reason

Could I do that?

What is the reason parameter in the event listener? Aren’t you passing it over when firing the event?

Issue 1: game.StarterGui.AdminPanel.KICKCMD.Reason == reason is a boolean because you are comparing reason with another value (if the kick reason is being supplied by the event call, what’s the point of this line?).

Issue 2: You’re supplying the reason as an argument to the Player:Kick() method instead of concatenating it to the string "Kicked for". The correct way to do this would be "Kicked for" .. reason.

1 Like

Use this:

local Players = game:GetService("Players")
local Remote = game.ReplicatedStorage.KICK

local admins = {528285072}

Remote.OnServerEvent:Connect(function(player1, targetUsername, reason)
	local reason = player1.PlayerGui.AdminPanel.KICKCMD.Reason.Text
	if not table.find(admins, player1.UserId) then return end
	local player2 = Players:FindFirstChild(targetUsername)
	if not player2 then return end 
	player2:Kick("Kicked for: ".. reason)
end)

TextBoxes don’t replicate to the server when edited by a player, so you have to pass it as a remote argument.

Something like this:

--Client
Remote:FireServer("username", "reason")


--Server
Remote.OnServerEvent:Connect(function(player1, targetUsername, reason)
	if not table.find(admins, player1.UserId) then return end
	local player2 = Players:FindFirstChild(targetUsername)
	if not player2 then return end 
	player2:Kick("Kicked for", reason)
end)

Show the script that fires the event. @aced_jkl

Would you not need to do this?

local Players = game:GetService(“Players”)
local Remote = game.ReplicatedStorage.KICK

local admins = {528285072}

Remote.OnServerEvent:Connect(function(player1, targetUsername, reason)
	local reason = game.StarterGui.AdminPanel.KICKCMD.Reason == reason
	if not table.find(admins, player1.UserId) then return end
	local player2 = Players:FindFirstChild(targetUsername)
	if not player2 then return end 
	player2:Kick("Kicked for"..reason)
end)

Doing :kick(“Reason For:”, Reason) will not work cuz you can only add a message on the kick as stated in the doc.

Player:Kick (roblox.com)

If the above code does not work can you print out the reason cuz it probs would be an issue with the other side.

Um also why are you kicking them client side? Could you not just do it via the server. Someone could exploit this system I feel like.

1 Like

What @LifeDigger says is correct. You need to concatenate (combine) your reason with your string like this:

Player2:Kick(“Kicked for”..reason)

Also, as @LifeDigger said, you should kick them via the server. Kicking from clients is very easily exploitable and hackers can kick whomever they want.

How would I go around making this exploit proof

No joke just kick from the server. From reviewing ur code I really don’t think there is a reason you have to kick them from the client side.

I really think everything that your wanting to do can easily be done via the server and no need to do any request to the client side unless I am incorrectly understanding what your looking for.

Nevermind guys its because I was trying to index it and the script is a serverscript and wasn’t actually going into the GUI text.