I am trying to move a model to a random position using math.random() but for some reason I get an error saying "Unable to cast double to Vector3" here is the code:
while PizToClone <= Piztobe do local copyPizza = Pizza:Clone() copyPizza.Parent = workspace.Pizzas copyPizza:MoveTo(math.random(198, 210), 231,math.random(31,41)) --This is the line giving me trouble print(copyPizza.Position.X, copyPizza.Postition.Y, copyPizza.Position.Z) PizzaCounter += 1 print(PizToClone) print(PizzaCounter) end
Hello.
The reason that you are experiencing this is because MoveTo expects Vector3.
You are not providing a Vector3, you are simply providing 3 numbers.
You can do this correctly by incasing those numbers with a Vecto3, like so:
copyPizza:MoveTo(Vector3.new(math.random(198, 210), 231,math.random(31,41)))
Best of luck!