Moving models using variables

  1. What do you want to achieve?
    I want to move a model to a position in workspace using a variable

  2. What is the issue?
    I have no idea how to do this

  3. What solutions have you tried so far?
    I have tried putting parenthesis around targetcombine and thats it.

-- wait(1)
local targetnumber = 1
local pieces = game.ReplicatedStorage.Pieces:GetChildren()
local randomPiece = pieces[math.random(1, #pieces)]
local targetFolder = game.Workspace.Targets
print(randomPiece)

local clonedpiece = randomPiece:Clone()
clonedpiece.Parent = workspace
local targetcombine = "CloneTarget"..targetnumber
print(targetcombine)
clonedpiece:MoveTo(targetFolder.targetcombine.Position)

Try using Model:PivotTo instead. It uses a CFrame not a vector3 btw

1 Like

I tried using pivotTo but it doesn’t change the position

What is target combine? Is it like a part?

I was trying to make a variable that combines a number and CloneTarget

Can to

Try switching it to this:

targetFolder[`CloneTarget{targetnumber}`].Position

@1AmMeUwU New edits

Gave me this in the output
Unable to cast Vector3 to CoordinateFrame

Screenshot 2024-10-01 195859
maybe this is helpful

Try using this. It converts the string as well

Sorry I messed up I was using pivotTo instead of moveto it is working now