Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Using the function :Kick(). How would I use it???

Asked by
Myaxp 3
9 years ago

I am making a GUI with a group checker code thing I did, so when the player is "NOT" in the group then it will perform a 10 second countdown with a info text on it. When it reaches 0 it is supposed to use the function :Kick(). The only problem is I am not asking a name of the person to kick them I am simply asking whoever is not in the group after 10 seconds, kick them. How would you do that?

For the people who want a script :

Button = script.Parent -- Note this is not a button. This is a TextLabel(Don't ask why it is named button)
Menu = script.Parent.Parent -- Ignore the 2 buttons as it is for something else on the GUI.
Menu2 = script.Parent.Parent.Parent
wait(1)

--This is not in a Local Script as all it does is remove the player rather than disconnecting them(I DO NOT WANT THEM TO CRASH!!!)

if script.Parent.Parent.Parent.Group.Value == false then
    Menu.Visible = true
    wait(1)
    Button.Text = ("Force Kick In - 9")
    wait(1)
    Button.Text = ("Force Kick In - 8")
    wait(1)
    Button.Text = ("Force Kick In - 7")
    wait(1)
    Button.Text = ("Force Kick In - 6")
    wait(1)
    Button.Text = ("Force Kick In - 5")
    wait(1)
    Button.Text = ("Force Kick In - 4")
    wait(1)
    Button.Text = ("Force Kick In - 3")
    wait(1)
    Button.Text = ("Force Kick In - 2")
    wait(1)
    Button.Text = ("Force Kick In - 1")
    wait(1)
    Button.Text = ("Force Kick In - 0")

    game.Players:connect(function(Player)    -- Like how does this work ????
        Player:Kick()
    end)
end

1 answer

Log in to vote
0
Answered by 9 years ago

Here is an example of one I made a while back, this will work with filtering enabled:-

Localscript, this is just a button in the starter gui:-

script.Parent.MouseButton1Click:connect(function ()
    game.Workspace.disconnectPlayer:FireServer() --The location of the remove function
end)

Server script:-

local event = Instance.new("RemoteEvent") 
event.Parent = game.Workspace -- This needs to be somewhere the player can access
event.Name = "disconnectPlayer" 
--You can create the object but decided to create on in this script


event.OnServerEvent:connect(function(plr,msg)  --Player name is passed to the script
    local gplr = game.Players:FindFirstChild(plr.Name) --finds the player in Players
    gplr:Kick()  --kicks the user 
end)

The above example shows you how it works but I need a little more information before I can fully answer your question, do you want the player to be kicked if when they join the game they are not part of the group?

Edit:-

Here is the script which needs to be ran on the server:-

local groupID = 372 --scriptinghelpers group id

game.Players.PlayerAdded:connect(function (plr)

    if plr:GetRoleInGroup(groupID) == "Guest" then --Guest is returned if not in group

        local Gui = plr.PlayerGui --gets the players gui

        for i=1, 10 do
            --add any gui changes here

            Button.Text = "Force Kick In - " .. i -- use a loop so there is less repeted code
            wait(1)
        end

        --Kick the player as they are not in the group  
        plr:Kick()
    end 

end)

All you need to do is add any gui changes in using the "Gui" variable e.g. Gui.ScreenGui.Frame.TextBox.Text

Hope this helps

0
Not straight away. In other words. When they join, the script counts to 10 and then kicks them. I have the group thing sorted I was just wondering how the function :Kick() would work. Myaxp 3 — 9y
0
The kick function will only work on the server and you need to kick the game player. e.g game.Players.[player name]:Kick() User#5423 17 — 9y
0
However I would like to kick the player "WITHOUT" defying a player name. Myaxp 3 — 9y
0
This script will only kick a player if they are not part of the group. As soon as the player is part of the group and they join the server then they will not be kicked, it does not kick a player depending upon their name. Also I have added the script in the edit User#5423 17 — 9y
Ad

Answer this question