Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Attempt to index nil with 'Kick' Problem?

Asked by 2 years ago

My code appears an error along the lines of " Attempt to index nil with 'Kick' "

Here is my code:

local plname = script.Parent.Text

script.Parent.MouseButton1Click:Connect(function() local plr = game.Players:FindFirstChild(plname) plr:Kick("You have been kicked by a moderator.") end)

If anyone knows the problem please tell me.

0
is it a localscript? imKlevi 94 — 2y
0
yes NotDrReplayz 0 — 2y
0
you can't kick through localscripts, you got to use remote events to do that imKlevi 94 — 2y
0
so an fire server i should do it though? NotDrReplayz 0 — 2y
View all comments (4 more)
0
You can kick on LocalScript - but you can only kick yourself though. However, that question is currently irrelevant; since we're talking about index nil, not attempt to kick other client NotThatFamouss 605 — 2y
0
Correct me if I'm wrong, but you're using a TextBox, correct? NotThatFamouss 605 — 2y
0
Button NotDrReplayz 0 — 2y
0
Make a local script which fires a remote event when the button is clicked and then make a script when detects when the remote event has been fired and then kick the player ghostbettert 30 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

I don't really get what you're trying to make..? TextButton isn't customizable unless if it was being controlled by a script. But I'm assuming this is what you're looking for.

Insert a RemoteEvent in ReplicatedStorage, then insert this script (localscript) in the button.

local Players = game:GetService("Players")
local RS = game:GetService("ReplicatedStorage")

local Event = RS:WaitForChild("KickEvent") -- Change KickEvent to your RemoveEvent name

script.Parent.MouseButton1Click:Connect(function()
    Event:FireServer(script.Parent.Text)
end)

Then insert a server script in serverscriptservice

local Players = game:GetService("Players")
local RS = game:GetService("ReplicatedStorage")

local Event = RS:WaitForChild("KickEvent") -- Again, change it

Event.OnServerEvent:Connect(function(plr, target)
    local plrToKick = Players:FindFirstChild(target)
    if plrToKick then -- Sanity Check
        plrToKick:Kick("\n You have been kicked by a moderator") -- \n means new line
    end
end)

Unless if you want to kick yourself then...

Client

script.Parent.MouseButton1Click:Connect(function()
    game.Players.LocalPlayer:Kick()
end)
Ad

Answer this question