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

attempt to index nil with 'Kick'?

i am making a game where if you press the wrong gui button, you will get kicked out. I tried both local and server scripts. This is my script:

script.Parent.MouseButton1Click:Connect(function(plr)
	local player = game.Players:GetPlayerFromCharacter(plr)
	player:Kick("Wrong Answer. Please try again.")
end)

I may be stupid and I probably shouldn't use GetPlayerFromCharacter. This is the error in the output:

  19:56:20.510 - Players.RealJefff2000.PlayerGui.ScreenGui.question1.answer2.Script:3: attempt to index nil with 'Kick'

1 comment

0

There are no parameters provided by the MouseButton1Click signal

1 answer

✓ Accepted answer

Okay, so first of all it has to be a local script. You can easily define a player that clicks it in a local script, so no GetPlayerFromCharacter function is needed. Here's how it should look:

local plr = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	plr:Kick("Wrong Answer. Please try again.")
end)

If you have any other questions, feel free to ask.

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