Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why cant I move this model to a random position?

Asked by 3 years ago

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
0
Not too familiar with :MoveTo() but doesn't it take a Vector3 as its argument? ex copyPizza:MoveTo(Vector3.new(math.random(198,210), 231, math.random(31, 41))) doc: https://developer.roblox.com/en-us/api-reference/function/Model/MoveTo msuperson24 69 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

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!

0
Thank you GatorDevv 6 — 3y
Ad

Answer this question