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'?

Asked by 4 years ago

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'
0
There are no parameters provided by the MouseButton1Click signal Ziffixture 6913 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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.

Ad

Answer this question