Ad
Log in to vote
1

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

Asked by 1 month ago

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.

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 Xzenerne 0 — 1mo

2 answers

Log in to vote
1
Answered by 1 month ago

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.

0
Definitely true. if there is nothing to find u'll find nothing. definitely. TheEagle722 114 — 1mo
0
Also make sure It is not in a localscript! TheEagle722 114 — 1mo
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. YoureTotallyScrewed 9 — 1mo
Ad
Log in to vote
0
Answered by 1 month ago

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.

Answer this question