Hello! I'm experimenting with scripting so I'm fairly new, and I wanted to create a button that can kick you from the server.
01 | FateButton = workspace.killroom.KBcontrolpanel.KILLBUTTON |
02 | function death(gb,msg) |
03 | FateButton.Part.SurfaceGui.TextLabel.Text = (gb) |
04 | print (msg) |
05 | return |
06 | end |
07 | FateButton.SurfaceGui.TextButton.MouseButton 1 Click:Connect( function () |
08 | local plr = game.Players:FindFirstChild() |
09 | FateButton.SurfaceGui.Enabled = true |
10 | death( "You clicked the kick button, you are now being kicked." , "Kicking player.." ) |
11 | wait( 3 ) |
12 | plr:Kick( "Kicked because you pressed the kick button" ) |
13 | end ) |
The output says line 8 is wrong because "Argument 1 missing or nil." This is outside of my small circle of knowledge about Lua scripting, so if anyone knows about it, please help.
Line 8 local plr = game.Players:FindFirstChild()
uses the built-in function :FindFirstChild
, which requires the first parameter as the child to look for. You can't find a child if you provide no child name.
Rather than doing FindFirstChild()
, try doing
01 | FateButton = workspace.killroom.KBcontrolpanel.KILLBUTTON |
02 | function death(gb,msg) |
03 | FateButton.Part.SurfaceGui.TextLabel.Text = (gb) |
04 | print (msg) |
05 | return |
06 | end |
07 | FateButton.SurfaceGui.TextButton.MouseButton 1 Click:Connect( function () |
08 | local plr = game.Players.LocalPlayer |
09 | FateButton.SurfaceGui.Enabled = true |
10 | death( "You clicked the kick button, you are now being kicked." , "Kicking player.." ) |
11 | wait( 3 ) |
12 | plr:Kick( "Kicked because you pressed the kick button" ) |
13 | end ) |
As FindFirstChild()
Needs an argument of which part or object you are trying to find.