Trying to create new randomly sized sprite, rand confusion

Godot Version

4.5

Question

I`m trying to take a sprite 2d and randomize the size of it, as a starter project, since im still new to coding/ the engine. The func to clone the sprite is something i saw as a solution on another post, so i grabbed it and used it, but if anyone has any other ways to clone nodes/ sprites id like to know about those too. BUT, the main issue this post was made for was the 2 lines i made , labelled 1 and 2. i get one error per line saying “Value of type “float” cannot be assigned to a variable of type “Vector2”.” , so i tried using randi instead, and it said it cant be an integer either. i thought that maybe i needed a way to make 2 random numbers at the same time and then i could set the x and y together, but i just cant think of a way to do that, i mean im gonna keep trying but help is appreciated.

TLDR, i wanna randomize the size of this sprite 2d but ive got 3 core confusions

  1. am i accessing the size correctly?
  2. is this the best way i could be doing this?

3.how am i supposed to randomize these values? i read the docs and couldnt find a " oh this is how you randomize 2 values at the same time"

, so, just to be ultra clear

goal: random x and y value for the sprite , problem : dont know how

If you share code, please wrap it inside three backticks or replace the code in the next block:

extends Node
var Hp = 100
var RNG = RandomNumberGenerator.new()
func Newsprite(sprite_2d: Sprite2D) -> Sprite2D:
			var new_sprite2d: Sprite2D = sprite2d.duplicate()
			new_sprite2d.transform.x = randf()#1
			new_sprite2d.transform.y = randf()#2
			add_child(new_sprite2d)
			return new_sprite2d

So first of all, you don’t need to seed the random number generator, and you’re not doing it right anyway. Second, to make a Vector2 use Vector2(). Third, you don’t want to set the transform. I’ve re-writen your code to follow the GDScript Style Guide.

extends Node

var hp = 100


func new_sprite(sprite_2d: Sprite2D) -> Sprite2D:
	var new_sprite_2d: Sprite2D = sprite_2d.duplicate()
	new_sprite_2d.scale = Vector2(randf(), randf())
	add_child(new_sprite_2d)
	return new_sprite_2d