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?
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?
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
Oh. Doy! Thanks!
No problem :D
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?
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.
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).
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.
2 comments
Try game.Players.LocalPlayer
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)