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

Help with kick script?

Asked by
unmiss 337 Moderation Voter
9 years ago

So, I have a textbox, and a textbutton. I want it so that when you type in the name of a player in the textbox, then click the textbutton, it kicks the player you typed in.. but I'm quite stumped. Any help? I'm not sure how to return what's typed in, to kick that player from game.Players.

I suppose you could consider this asking for help without having code.. but there's not much code for me to include other than defining variables:

local playerwk = game.Players.LocalPlayer -- player who kicked (to log that they kicked someone in a hint)
local offender = script.Parent.Parent.Offender -- textbox, the offender that you're trying to kick

function kickplr()

end
0
Cmon! I'm trying to get reputation too! EzraNehemiah_TF2 3552 — 9y

3 answers

Log in to vote
2
Answered by
ImageLabel 1541 Moderation Voter
9 years ago

Text Outline

  • clicked
  • Check TextBox's Text property
  • If Text is a valid player
  • Kick

Code

Offender = textboxyouwanttocheck 

isPlayer= function(text) --checks if player is in players service 
    return game.Players:FindFirstChild(tostring(text)) or nil
end

TextButton.MouseButton1Down:connect(function()
    local playerFromTextBox = isPlayer(Offender.Text)
    --  store returned value from function call in variable 

    if playerFromTextBox then 
                --if player is not nil 
        --kick
    end
end)
0
Is there a chance you could use the variables I defined to assist myself in understanding this better? unmiss 337 — 9y
Ad
Log in to vote
2
Answered by 9 years ago

To get what the player typed into the text box, you need to see the text box's text property.

local textbox = script.Parent
print(textbox.Text)

There is a Kick method so you could kick people...

game:GetService("Players").player:Kick()

You could also put a string inside the "()" so you could add a custom message.

local playerwk = game.Players.LocalPlayer -- player who kicked (to log that they kicked someone in a hint)
local offender = script.Parent.Parent.Offender -- textbox, the offender that you're trying to kick

function kickplr()
    local kick = game:GetService("Players"):FindFirstChild(offender.Text)
    if kick then
        kick:Kick(playerwk.Name.." has kicked you.")
    end
end

Hope it helps!(My answer is better lolololol. maybe.)

0
yours worked too, just uh giving points to him since he's lower unmiss 337 — 9y
0
no TabToChat 0 — 3y
Log in to vote
0
Answered by 4 years ago

I know that this has already been answered, but it can be re-answered, this is a lot easier than the other answers. Put this LocalScript inside the kick button.

local PlayerTK = game.StarterGui.ScreenGui.KickUI.textbox
local PlayerWK = game.Players.LocalPlayer.Name

script.Parent.MouseButton1Down:Connect(function(Kick)
game.Players[PlayerTK]:Kick(¨You were kicked by ¨..PlayerWK)
end)

If it doesn´t work, be aware that I haven´t scripted for a LONG time.

0
Why would you reply to something 4 years old with something blatantly wrong and stupid? unmiss 337 — 4y
0
Why would YOU *consider* doing it before seeing somebody else already did it and then change Your mind?? :) It does work, I just forgot to include a FireServer. Your brain was blatantly wrong and stupid before commenting this. Sk3pticalR0BL0X 33 — 4y

Answer this question