Attempt to index local player, a nil value

Hey guys,
So i’ve received this error several times in the past and found a way around it, but for some reason I can’t find the solution to this…conundrum.
The gui button , when clicked gives this error :

image

My script in the gui button, (a local one)

local Players = game:GetService("Players")
local player = Players.LocalPlayer

       script.Parent.MouseButton1Click:Connect(function(player)--not keeping player here has no effect on the problem  either
             if player== nil then 
	     return print(player.Name.."is nil for some reason..")
        end
  print("connected")
    local character = player.Character or player.CharacterAdded:wait()
      local humanoid = character:FindFirstChild("Humanoid")

		 humanoid:RemoveAccessories()
		       print("removed")
	     end)

I’ll appreciate any help. The roundify px etc…is from Roundify, the plugin by ZacBytes

MouseButton1Click doesn’t pass anything as an argument, so it doesn’t return anything. If you remove the player variable in the function as a parameter, the script would work fine.

script.Parent.MouseButton1Click:Connect(function() 
    -- code here
end) 
1 Like

Does that basically pass an argument for the function , for every player?
I mean because the script is replicated for each client after all.right?
So is there nothing at all we can add as a parameter in the function ?

No, MouseButton1Click doesn’t pass any values as an argument when it is fired, so you shouldn’t expect any parameters in the functions. The local script is cloned for each client, but only runs on their own client and won’t deal with other clients

1 Like