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)
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.