I get Access Violation using Spawn function

I am getting access violation on that line i marked and i dont understand why, was following a tutorial and it worked on their and but not mine, anyone have an idea whats up with it?

void AWMPlayerCharacter::BeginPlay()
{
	Super::BeginPlay();

    if (HasAuthority())
    {
        for (const TSubclassOf<AWeapon>& WeaponClass : DefaultWeapons)
        {
            if (WeaponClass == nullptr) continue;

            FActorSpawnParameters Params = FActorSpawnParameters();
      
            AWeapon* SpawnedWeapon;
            --->SpawnedWeapon = GetWorld()->SpawnActor<AWeapon>(WeaponClass, Params);
            const int32 Index = Weapons.Add(SpawnedWeapon);
            CurrentWeapon = SpawnedWeapon;
            OnRep_CurrentWeapon(nullptr);
        }
    }
	
}