Problems with getting the player

Hello. I’m trying to connect this in a DataStore when a player leaves the game. It works perfectly for the coins but I’m trying to save a different Value in the PlayerGui. But for some reason it says that PlayerGui is not a valid member of Player. If you guys could help me out that would be great! Heres the script I have.

3 Likes

Datastores can’t have anything done to them from a client. It has to all be server sided aka (Script) not (LocalScript)

PlayerGui can only be accessed by a local script running on the client.

To solve your problem you would need a RemoteFunction. Have the server tell a local script what the Value you wish to save is, then have the local script return the Value to the server to be saved.

I’m not sure if this will work when the player is leaving due to the requested value not returning fast enough.

2 Likes

In addition, if you’re running a server script you can’t use Player.PlayerGui instead you would have to either use a RemoteFunction to :InvokeClient() or a RemoteEvent to :FireClient()

You also should be checking on the server instead of the client (PlayerGui) for whether the player owns those items to be secure and prevent exploiters from obtaining free items. Using remotes in this case will help you for player transactions for those items and store the properties in a table.

Alright Thanks for letting me know! To keep things easy I’m just going to make a folder in the player named Particle Values and I’ll change the UI scripts to redirect them there. Thanks again!

1 Like

Thanks for your replys It’s a huge help!