Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why cant I move this model to a random position?

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

1 comment

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

1 answer

✓ Accepted answer

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!

1 comment

0

Thank you

This discussion is preserved as it was. New answers, comments, and votes are closed.