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

¿Is there a way to clone and set the position of a MODEL?

Hi, so i´m just starting to code with LUA and Roblox and I am making a racing game in which the player will select in the beginning from a GUI which car they want to ride (yellow, red, blue, etc), but in this specific script I just want to do the test with the yellow one.

The problem that I have is that many players can select the same type of car, so I have the cars hidden beneath the map and I just need to clone them to an specific position depending on the players choice.

My question is if it is possible to set the position of a model or how can I clone a model but move it to a different position instead of the starter position itself.



local yellowCar = game.Workspace.yellowCarTest
local seat = yellowCar.VehicleSeat

--This function is to clone the Yellow Car
local function cloneYellow()
    local copyYellow = yellowCar:Clone()

    copyYellow:MakeJoints()
    copyYellow.Parent = game.Workspace
        copyYellow:MakeJoints()

    copyYellow.Position = Vector3.new(217.669, 59.275, -334.282)
end

--This functions is to close the GUI that will appear to the player
local function closeWindow() 
    local window = script.Parent.Parent.Parent.Parent.Parent.SelectCar
    window:Destroy()
end

--This function will be active when the car button is pressed
script.Parent.MouseButton1Click:connect(function()
    cloneYellow()
    closeWindow()
    --wait(1)

--Move the player to the car's seat
game.Players.LocalPlayer.Character.UpperTorso.CFrame = CFrame.new(seat.Position)
end)


If you need additional info just let me know, thank you!

1 comment

0

Models don't have positions

1 answer

✓ Accepted answer

The one way you could do it is by adding a PrimaryPart in it. Once you do that cloning the model and positioning will be easy

just use :SetPrimaryPartCFrame()

When I do this I add parts the same size as my primary and add them were I want to position it and set the CFrame to that parts Position.

local model = game:GetService("Lighting"):WaitForChild("Model"):Clone()

model.Parent = workspace
model:SetPrimaryPartCFrame()

6 comments

0

why are you using lighting as a storage space ??

0

Its just an example.

0

And you couldn't use ServerStorage or replicatedstorage ?

0

no

0

It worked perfectly for me, thank you so much!!

0

@incapaz Rep doesn't matter if you're content with helping people and happy doing so.

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