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

Help with kick script?

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

1 comment

0

Cmon! I'm trying to get reputation too!

3 answers

✓ Accepted answer

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

1 comment

0

Is there a chance you could use the variables I defined to assist myself in understanding this better?

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

2 comments

0

yours worked too, just uh giving points to him since he's lower

0

no

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.

2 comments

0

Why would you reply to something 4 years old with something blatantly wrong and stupid?

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.

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