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

I made a kick script but it wont work, it gives me an error. Can someone fix this?

I try to make a kick button that kicks the player name that is entered in the box. I already made a script but when i try it i get an error saying: "17:19:56.731 - Players.Player1.PlayerGui.ScreenGui.TextButton.Script:4: '' expected near '('"

Does anyone know how i fix this?

local player = game.StarterGui.ScreenGui.Player.Text

function kick()
game.Players.(player):remove("Kicked from server.")
end

script.Parent.MouseButton1Down:connect(kick)

1 comment

0

You should user game.Players[player]:Kick("Reason") instead, also you're reading text out of starterGui. Might want to look into that..

1 answer

The main problem here is that you're trying to find the player with the name, but you're going about it the wrong way. This is the proper way to access an object with a variable:

game.Players[player]:remove("Kicked from server.")

Another issue is that remove() has long since been deprecated, and you should use Kick() instead:

game.Players[player]:Kick("Kicked from server.")

Finally, whoever is using the kick script may accidentally type in a wrong name, so you need to check to make sure that the player is actually there:

local playerToKick=game.Players:FindFirstChild(player) --find the player
if playerToKick then --see if the player exists
    playerToKick:Kick("Kicked from server.") --kick the player
end --close the statement

I hope this helped!

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