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

Kicking via LocalScript?

Asked by
emite1000 335 Moderation Voter
9 years ago

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?

1
Try game.Players.LocalPlayer M39a9am3R 3210 — 9y
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) Sk3pticalR0BL0X 33 — 4y

3 answers

Log in to vote
1
Answered by 9 years ago

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
0
Oh. Doy! Thanks! emite1000 335 — 9y
0
No problem :D fahmisack123 385 — 9y
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? emite1000 335 — 9y
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. fahmisack123 385 — 9y
View all comments (2 more)
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). emite1000 335 — 9y
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). emite1000 335 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

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!

Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
9 years ago

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

Answer this question