Attempt to index nil with 'OnClientEvent'

today i tried to make a inventory gui and it worked, after that i tried to make a collect item system but for some reason everytime i launch play, the collect button on the item doesnt show up and it shows this error in the console ‘‘attempt to index nil with ‘OnClientEvent’’’

this is the script that is giving errors:

client.OnClientEvent:Connect(function(material)
button.Visible = true

i tried my best to fix it but im not being capable of

If it is a local script, you should use “OnServerEvent” as the server fires the event.

so i should change OnClientEvent to OnServerEvent?

Depends on what is your script its local script or server script

The object named “client” may not be a remote event. Double check if it is.

The error is saying that the variable client is nil. Can you show us what this variable is assigned to?

If this is a localscript

Then in the script you should put

Event:FireClient(PlayerToSendThingTo)
1 Like