Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

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

Asked by 2 years ago

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!

0
Models don't have positions User#19524 170 — 2y

1 answer

Log in to vote
0
Answered by
uhTeddy 101
2 years ago

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()
0
why are you using lighting as a storage space ?? User#19524 170 — 2y
0
Its just an example. uhTeddy 101 — 2y
0
And you couldn't use ServerStorage or replicatedstorage ? User#19524 170 — 2y
0
no uhTeddy 101 — 2y
View all comments (2 more)
0
It worked perfectly for me, thank you so much!! JPINAG98 2 — 2y
0
@incapaz Rep doesn't matter if you're content with helping people and happy doing so. TheeDeathCaster 2319 — 2y
Ad

Answer this question