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.
FateButton = workspace.killroom.KBcontrolpanel.KILLBUTTON function death(gb,msg) FateButton.Part.SurfaceGui.TextLabel.Text = (gb) print(msg) return end FateButton.SurfaceGui.TextButton.MouseButton1Click:Connect(function() local plr = game.Players:FindFirstChild() FateButton.SurfaceGui.Enabled = true death("You clicked the kick button, you are now being kicked.","Kicking player..") wait(3) plr:Kick("Kicked because you pressed the kick button") 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
FateButton = workspace.killroom.KBcontrolpanel.KILLBUTTON function death(gb,msg) FateButton.Part.SurfaceGui.TextLabel.Text = (gb) print(msg) return end FateButton.SurfaceGui.TextButton.MouseButton1Click:Connect(function() local plr = game.Players.LocalPlayer FateButton.SurfaceGui.Enabled = true death("You clicked the kick button, you are now being kicked.","Kicking player..") wait(3) plr:Kick("Kicked because you pressed the kick button") end)
As FindFirstChild()
Needs an argument of which part or object you are trying to find.