Welcome to the forums @pierre_josselin!
I would recommend using an array for this. Store all of the position nodes in an array, use a for
loop going from 0 to 4, randomly select one of the positions in the array, spawn/instance the coin and the correct position, and then remove the position from the array. Something like this (untested):
# I am going to assume the script is attached to the
# PossibleCointsPositions node for simplicity.
# Additionally, I will assume the coin scene is
# preloaded into a variable called COIN_SCENE
# Finally, this code should be in a function (like _ready)
var positions_array = []
# if the children are only positions:
for child in get_children():
positions_array.append(child)
# if not, you will need to populate the array manually
# positions_array.append(get_node("Position1"))
# positions_array.append(get_node("Position2"))
# positions_array.append(get_node("Position3"))
# ... and so on.
# spawn four coins using a for loop
for i in range(0, 4):
# get a random number between zero and the number of elements in the array
var coin_spawn_index = round(rand_range(0, positions_array.size()-1))
# get the node in the array at the random position
var coin_spawn_node = positions_array[coin_spawn_index]
# make a new coin
var coin_clone = COIN_SCENE.instance()
# add the coin to the scene
add_child(coin_clone)
# position the coin at the coin_spawn_node
coin_clone.global_position = coin_spawn_node.global_position
# finally, remove the spawn position from the array
positions_array.remove(coin_spawn_index)
# (optional: print to know a coin was placed)
print ("Coin placed!")