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

Kicking via LocalScript?

So I have a blank LocalScript in the StarterGui.

I have

script.Parent.MouseButton1Click:connect(function()
LocalPlayer:Kick()
end)

inside of a GUI button.

So why is it that when I click the GUI button I don't get kicked?

2 comments

1

Try game.Players.LocalPlayer

0

Well, you need game.Players.LocalPlayer, also, if it is a LocalScript, nobody will see your character leave until you actually press the leave button (On new roblox disconnected gui)

3 answers

✓ Accepted answer

Azarth (Another guy who answered this question), seems to know more than me. Here's the script... Remember, it needs to be in a normal script...

script.Parent.MouseButton1Click:connect(function(p) --Calls the function and declares the player as "p"
p:Kick() --Obvious...
end)--Ends the function

6 comments

0

Oh. Doy! Thanks!

0

No problem :D

0

Wait, so it worked when I tested it out in Studio, but when I try it in the actual ROBLOX player nothing happens. What's the problem?

0

Go to the real server, press CRTL+F9 and tell me what the output says when you click the button... Then I can fix it.

0

It says xxxxxxxx.Frame.Quit.Script:2: attempt to index field 'LocalPlayer' (a nil value). (xxxxxxxx = the pathway down to my GuiButton called 'Quit'. No point in typing it all).

0

How does saying (function(p) define p as the player? Also, I tried it and sure enough it said I tried to target p (a nil value).

Hmm, try this;

script.Parent.MouseButton1Click:connect(function() --If the Scripts Parent is in the TextButton, then this will work
if game:FindService("Players")and game.Players.LocalPlayer and game.Players.LocalPlayer.Character and game.Players.LocalPlayer.Character:FindFirstChild("Humanoid")then --If script finds service Players within Game, LocalPlayer exists (As a just incase :P), LocalPlayer's Character exists, and LocalPlayer's Character's Humanoid exists then
game.Players.LocalPlayer:Kick() --Kicks LocalPlayer
end end) --All the ends for the script

I hope this helped!

You can't use the Kick() method in a LocalScript, use a RemoteFunction to communicate with a script to do it.

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