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

Attempt to index nil with 'Kick' Problem?

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.

8 comments

0

is it a localscript?

0

yes

0

you can't kick through localscripts, you got to use remote events to do that

0

so an fire server i should do it though?

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

0

Correct me if I'm wrong, but you're using a TextBox, correct?

0

Button

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

1 answer

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)

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