Button Clicked, Read TextBox Information and Kick Not Working Correctly

Issues with Button Kick Functions for Admin GUI

So I have just had a issue this morning in roblox studio about coding kick functions when you type Reasons/Usernames into the TextBox, my code consists of…

function Clicked() 
	game.Players.(script.Parent.Text):Kick(script.Parent.Parent.Reason.Text)
end
script.Parent.MouseButton1Down:connect(Clicked)

I have coded a script that will… ``` When clicked a GUI… it will look into game.Players and then look into a TextBox to see what player the admin/mod had typed in for the player to kick, and then a reason on what they typed in a different text box, and I am getting a error saying telling me:image
But this error is appearing only when i join the server, when i want it to function the script when you click the Kick button as shown in the video below:

If anyone knows what the sullotion could be please leave a comment below because I am making a game, currently developing a Admin Panel for when where Testing. Thanks :smiley:

1 Like

You cannot get a child of an object with .string. To use a string for this use brackets.

function Clicked() 
	game.Players[script.Parent.Text]:Kick(script.Parent.Parent.Reason.Text)
end
script.Parent.MouseButton1Down:Connect(Clicked)

Also, check to make sure the text is a player’s name in the game.

function Clicked() 
    if game.Players:FindFirstChild(script.Parent.Text) then
	     game.Players.(script.Parent.Text):Kick(script.Parent.Parent.Reason.Text)\
    else
        print("Player not found!")
    end
end
script.Parent.MouseButton1Down:Connect(Clicked)
2 Likes

This has to be a localscript as the server cannot see local changes.
You can then use a RemoteEvent and do :FireServer().

More about RemoteEvents:

1 Like

Here is your issue.

game.Players.(script.Parent.Text):Kick(script.Parent.Parent.Reason.Text)

you are doing (script.Parent.Text), which is wrong.
An alternative to do would be

game.Players[script.Parent.Text]:Kick(script.Parent.Parent.Reason.Text)

We are using brackets because doing () when doing game.Players. will error.
So, using brackets will help.

Also, doing this cliently will not work.
I suggest doing remote events.

Using the remote event as a server script as the reciever, it will be able to kick players from the game.
while locally, it will not work as they do not have permission to.
Client is you for example, and the server is the actual game.

Some extra information regarding this topic:

The reason why a client cannot kick another client via a localscript is because it does not replicate to the server.

And, if you attempt to to kick a player if they meet a certain condition, a exploiter can cancel the :Kick() packet being sent to their client.
(ex, if you had a localscript detecting if their WalkSpeed is above a certain number).

Your best bet would be to crash them instead (while true do end).

3 Likes

yeah.
zxzxvvzvzcxxcxccxcxxcvxccxvcxvc

My output has run a error stating that Kick is not a valid member of Players, i dont know but it may not recognize the brackets.
image

1 Like

Use remote events, the server script as the reciever, and the client script as the sender.
Client cannot kick players. Only the server can because they are basically the game itself.

2 Likes

I made an example below:

--[[ <-> localscript <-> --]]
local Event = game:GetService('ReplicatedStorage'):WaitForChild('RemoteEvent')
-- your code including:
Event:FireServer(Username, Reason)


--[[ <-> serverscript <-> --]]
local Players = game:GetService('Players')
local Event = game:GetService('ReplicatedStorage').RemoteEvent
Event.OnServerEvent:Connect(function(Player, Username, Reason) -- Player is automatically sent to the server.
	--[[
		you should probably whitelist the players that is allowed to use this,
		as any exploiter can call FireServer() with their own arguments and kick whoever they want.
	--]]
	local TargetPlayer = Players:FindFirstChild(Username)
	if TargetPlayer and Reason:find('%w') then
        -- check if the reason contains a alphanumeric character (0-9, a-z)
		TargetPlayer:Kick(Reason)
	end
end)

Hope this helps.

Keep in mind that you need to create a RemoteEvent inside the ReplicatedStorage service.