Issues with velocity, positioning and instantiation(read clarification)

Godot Version

4.3

Question

Ask your question here! Try to give as many details as possible
I am new to Godot, and am trying to make a simple game where a moving ship fires a cannon. I am able to get the duplicates to go to the player. However,when I try to set the velocity of the duplicates, or try to just make them all the same velocity, they all move relative to each other, and do not start at the player. I have tried a few solutions I found on a few other forums. This is the code in its earlier state. It doesn’t seem to work whether I am attempting to change either the duplicate properties or the original object.
`extends CharacterBody2D
var cpl = preload(“res://assets/scenes/cannonball.tscn”)
@onready var timer: Timer = $Timer
@export var cannondirection = 0
var cannonspeed = 50
@onready var player: CharacterBody2D = $“…/player”
func fireCan():
var instancecb = cpl.instantiate()
instancecb.set_process(true)
instancecb.position= player.position
add_child(instancecb)

func _process(delta: float) → void:
if Input.is_action_just_pressed(“cannon”):
fireCan()
velocity.x = cannonspeed
move_and_slide() `
Any help is appreciated
-clarification: the behavior I experience is I fire the cannon, the ball shoots out, I fire again, after having moved forward, and the cannonball appears in front of the other cannonball, moving at the same speed, at the same distance the other ball was previously to the player.

Children’s positions are added to their parent’s position. Since you are adding the cannonballs as children of the ship, when the ship moves, the cannonballs also move with it. You should instead add the cannonballs as a child of a node that does not move.

Cannonballs are their own thing; they aren’t a child of the player. They only go to the position. The problem is that when the cannonballs are created, they have moved with the player, but the velocity of the balls apparently means they are spawned the same distance away as the cannonballs that already exist.

After further trial and error, I realized that the script was outside of the scene, and was not being referenced.