How to tell if player is in-game

I have a coin-giving system. It changes the datas directly from the datastore of a player that i give coisn to. it works if the player is not in game but if the player is in game, then when I give the coin, it saves to the datastore. but it does not update the coins from the datastore for obvious reasons. so when they leave, it saves again and so basically removes the coins given. i can’t just use game.Players:FindFirstChild(playerName) because they can be in another game server. how do I do it?

1 Like

Not really sure if this could work but have you tried making a table for the players in the current server?

1 Like

Datastores? They can continue between servers.

1 Like

maybe i don’t get it, but just don’t save the coins when player leaves if they are already being saved the second someone got them

1 Like

I think I know a way you can do this. When giving coins, get the player’s userId first. Then, use TeleportService:GetPlayerPlaceInstanceAsync() to detect if the target player is playing in a server of the game (matching placeId). If they are in a server of the game, use MessagingService to broadcast their userId and coin amount to be received. The other servers will then attempt to get the player by their id. If this succeeds, then this gives them the coin(s) directly. If the player is not in a server of the game, simply update their data from the current server.

1 Like