
^ This is a script
I get an error saying “Player should be of type Player, but is of type nil”
I feel as this should work perfectly fine.
Any help would be appreciated!

^ This is a script
I get an error saying “Player should be of type Player, but is of type nil”
I feel as this should work perfectly fine.
Any help would be appreciated!
This is in a LocalScript, correct? If so, where is it located?
The issue is that you put player as the first parameter of the .MouseButton1Click function which is nil because the event does not give anything. Try taking out player from the function which will leave it with no parameters. Also here is the documentation for the .MouseButton1Click event.
You’re changing the value of “player” when the button is clicked. PLAYER is not passed when a GuiObject is pressed, remove that completely. You’re overwriting it with nil.
Try to remove “player” argument in function. Also check that your script is LocalScript because a normal script is not able to change the User Interface,so all operations that are performed with the Gui are written in LocalScript .
It was a local script but It didn’t work so then I changed it to a normal script.
Apologies, I need to give more info, This is a SurfaceGui, which has a purchase button with a script instead of a local script.

This how I have written it now and still get the same error.
Okay, you will have to use a LocalScript instead of a server Script because LocalPlayer is nil on the server.
When I use localScript Nothing happens.
Apologies, that was a mistake on my end. I forgot LocalScripts do not work in Workspace. An alternative you could use is a ClickDetector and its .MouseClick event which gives the player who clicked as its first parameter.
You said that you are using SurfaceGui. I advice you try to use ImageButton if it is Image on Surface. Or I advice you to use ClickDetector on your image.
Thanks Everyone for the help! I really Appreciate it!