I think the issue here is that the number of dots in a stimulus can’t be updated: it is set just once at the start of an experiment (notice how that field doesn’t have a popup menu next to it that specifies when the value gets updated).
If you want a dotstim with varying numbers of dots, I think you’ll need to create it in code rather than use the graphical dotstim component. i.e. insert a code component in Builder and in the “Begin routine” tab, insert code to create a stimulus afresh on every routine, using your variable name to control its number of dots. You’ll then also need to control its drawing, by either setting its outdraw attribute to true, or drawing it explicitly in the “every frame” tab.