Move a Part to a Specific Random Position

I have 3 specific places I want a part to go to, but I want to make it go to a random place of those three. Like keys in Piggy.

I currently have this script:

local letter = script.Parent
local posfolder = script.Parent.LocationsPos

local posnum = math.random(1,3)

if posnum == 1 then
	letter.Position = Vector3.new(posfolder.Loc1.Value)
elseif posnum == 2 then
	letter.Position = Vector3.new(posfolder.Loc2.Value)
else
	letter.Position = Vector3.new(posfolder.Loc3.Value)
end

image
image

Whenever I run the script, the part just goes to the spawn point.

How would I fix this?
Thanks.

1 Like

I think it’s cause you’re literally creating a new Vector3, so by default the script defines the Position as the Baseplate Origin (Or 0,0,0)
Just remove the Vector3.new?

Isn’t Vector3Value.Value already a Vector3.new() Object?
So I think you should just assign the letter’s position directly.

local letter = script.Parent
local posFolder = script.Parent.LocationPos

local posnum = math.random(1, 3)

if posnum == 1 then
    letter.Position = posFolder.Loc1.Value
elseif posnum == 2 then
    letter.Position = posFolder.Loc2.Value
else
    letter.Position = posFolder.Loc3.Value
end

No. Please see the Vector3 article at the Developer Hub, Position uses a Vector3 value.

It worked. Thanks @Jackscarlett and @minhnormal for the help.

1 Like

Yeah but the parameters still didn’t exactly work when he made a new Vector3, Idk it’s strange (I was able to replicate it)

1 Like

It didn’t work because of what @minhnormal said, posFolder.Loc1.Value is already a Vector3 value, although removing Vector3.new works your logic didn’t really make sense for me.

Oh, my bad then (I was thinking that a Vector3Value were just the X, Y & Z positions only, but not thinking that it was capable of that), guess you learn something new everyday