Spirte variable not changing correcttly

I Have a sprite with variable. I create the sprite at position and change the variable of created spirit. The problem is when I create a sprite the variable changes for all created sprite not only the last one.
while in the same action I create a text object which has also a variable and I change the variable same as a sprite , and it works fine.
What I am doing wrong here.

Use a for each object condition; then do the checking if the X and Y position of the touch matches the same as the coin, you then execute the code/action for the specific coin (whilst in your situation, do stuff with the sprite).

GDevelop applying an action to all instances instead of the one you’ve just created is an annoying problem that strikes at unpredictable times. One way to “trick” it into only acting on the object you’ve just created is to add a sub-event that checks a property of the object that should only apply to the new one - like checking the X and Y position as Rikazu suggests.

[Conditions for creating a coin] | Create object Coin at position Variable(touchX);Variable(touchY) |___The X position of coin =Variable(touchX) | Do = Variable(nextCoinValue) to variable scoreValue of Coin |___The Y position of coin =Variable(touchY) |

Instances picking is a dark art that needs a good article in the wiki, I keep discovering new things even after many years using GD :confused:
But I think the “Create object action” works this way:

  • If there is no previous condition/action (in the current or parent events) that pick instances of an object A, the action to create the object A picks that instance only, so future actions in this or child events will affect the created instance only.
  • If there are already picked instances (for example because of a condition like “Number of A is < 5”) in the current or parent events, the create object action just adds the new object to the picked list, and future actions will affect the previously picked objects plus the newly created one.

In base on this, I think there may be a condition (again, in the current or parent events) that picks some instances of the sprite/coin :slight_smile: