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