Why will my script not kick when you press the GUI?

Hi! i am trying to make a game but my script wont kick -.-

plr = game.Players.PlayerAdded:Connect()
button = script.Parent
window = script.Parent.Parent.Parent

function onClicked(GUI)
	window:remove()
	plr:Kick()
end
script.Parent.MouseButton1Click:connect(onClicked)

2 Likes

Use local variables, not global ones. Also, is this a local script? If so, you can just get the player with .LocalScript (and it should be a local script, avoid using server scripts on UI objects)

Both :remove() and :Remove() have been deprecated, use :Destroy()

So let’s clean up your code a little bit

local plr = game:GetService('Players').LocalPlayer
local button = script.Parent
local window = script.Parent.Parent.Parent

function onClicked()
	window:Destroy()
	plr:Kick()
end

button.MouseButton1Click:Connect(onClicked)
2 Likes

Thank you sorry im only a beginner coder U.U

1 Like
local Player = game.Players.LocalPlayer

local Button = script.Parent

local window = Button.Parent.Parent

local function onClicked()
Player:Kick()
end

Button.MouseButton1Click:Connect(onClicked)

Try that.

Your removing the window before you kick the player so the script will also be destroyed and won’t finish.

Since the GUI is local-sided. You should always use game:GetService("Players").LocalPlayer instead over the plr variable.