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

Click TextButton to get kicked from the server script doesn't work, can anyone help?

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.

1 comment

0

Trying doing local player rather than doing FindFirstChild. As FFC looks for the first child with a specific name (Argument 1) if you did

2 answers

✓ Accepted answer

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.

3 comments

0

Definitely true. if there is nothing to find u'll find nothing. definitely.

0

Also make sure It is not in a localscript!

0

Thanks for this answer! I always thought FindFirstChild would pick the child at the top of the list if no child was specified, but I guess I was wrong. Also I fixed the script by removing game.Players:FindFirstChild() and writing script.Parent.Parent, since the LocalScript is in the StarterGui.

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.

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