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

CFrame Cloning is that possible?

So. I am making an infinity obby where you can buy the obby peices how ever you want, so like "If i buy the first lavastage and then click it again then it clones twice but not at the same spot the other time you bought it then it gets a littlebit forwards then the other stage that you bought." But i dont know if this works or wat does. Just to specify LavaStage is a model

Here's the current script

local LavaStage = game.ServerStorage.LavaStage

function Clone()
	LavaStage:Clone()
	LavaStage.Parent = workspace
	LavaStage.CFrame = CFrame.new(0, 0, 0 + 2)
	
end

script.Parent.MouseButton1Down:connect(Clone)

2 answers

local LavaStage = game.ServerStorage.LavaStage

local Total = 1
function Clone()
	local New = LavaStage:Clone()
	New.Parent = workspace
	New:TranslateBy(Vector3.new(0, 0, 2 * Total))
	Total = Total + 1
end

script.Parent.MouseButton1Down:connect(Clone)

You were doing

LavaStage:Clone()

Without defining that object as a variable, so that cloned part never gets anything doing with it, and from there you edit the initial lavastage part within the serverstorage.

4 comments

0

I get this error "CFrame is not valid member of model"

0

And when i tried with not a model then it just went where i started i want it to be a littlebit forward then the other part like if the part is here then then if i buy another stage then it goes like 5 studs forward

0

Well, What is "local last" then?

0

Ok ive edited it to work with a model.

You need to set the starting CFrame and then add a Vector3 to it.

Here is an example:

local CD = script.Parent.ClickDetector

local CF = CFrame.new(0, 10, 0) -- Starting CFrame

function NewTycoonPart()
	local Part = Instance.new("Part", workspace)
	Part.Anchored = true
	Part.CFrame = CF + Vector3.new(0, 0, 5) -- Add a Vector3 to the CFrame
	wait(0.2)
	CF = Part.CFrame -- CFrame of the next part
end

script.Parent.ClickDetector.MouseClick:connect(function()
	NewTycoonPart()
end)

2 comments

0

But what if i wanna use a model? instead of creating a new part inside the script

0

Then set the parent of the part to the model. The second argument in "Instance.new("Part", workspace)" is the parent of the new part.

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