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

Generate to latest postition?

What I'm trying to do. I am trying to make it so that once a part is generated for my game the next one generates from the new position got from the previous generate. The problem is it only generates in front of the original block that the script executes from. (All of the blocks in the serverstorage are the same size)

Make a block then do everything below.

Block Size You must use this to test the script(12, 4.22, 24.43) Block Position This too. (-7.768, 2.11, 5.689)

Next you duplicate the block at the same position and put it in serverstorage and keep duplicating and type all the names below in all the blocks you duplicated then in the original block (not the ones in the serverstorage) is still suppose to be in workspace. and after that put this script into the original block.

hope i explained this right.

local OldPart_CFrame = 0

while wait(2) do 
local Choose = math.random(1,8)
if Choose == 1 then
	local Generate = game.ServerStorage.Default:Clone()
	Generate.Parent = workspace
	OldPart_CFrame = Generate.Position.Z -- Z Axis
	Generate.CFrame = Generate.CFrame * CFrame.new(0, 0, 19.2 + math.pi+2)
end
if Choose == 2 then
	local Generate = game.ServerStorage.Jumps:Clone()
	Generate.Parent = workspace
	OldPart_CFrame = Generate.Position.Z -- Z Axis
	Generate.CFrame = Generate.CFrame * CFrame.new(0, 0, 19.2 + math.pi+2)
end
	if Choose == 3 then
	local Generate = game.ServerStorage.Middle:Clone()
	Generate.Parent = workspace
	OldPart_CFrame = Generate.Position.Z -- Z Axis
	Generate.CFrame = Generate.CFrame * CFrame.new(0, 0, 19.2 + math.pi+2)
end
	if Choose == 4 then
	local Generate = game.ServerStorage.NoMiddle:Clone()
	Generate.Parent = workspace
	OldPart_CFrame = Generate.Position.Z -- Z Axis
	Generate.CFrame = Generate.CFrame * CFrame.new(0, 0, 19.2 + math.pi+2)
end
if Choose == 5 then
	local Generate = game.ServerStorage.SideLeft:Clone()
	Generate.Parent = workspace
	OldPart_CFrame = Generate.Position.Z -- Z Axis
	Generate.CFrame = Generate.CFrame * CFrame.new(0, 0, 19.2 + math.pi+2)
end
if Choose == 6 then
	local Generate = game.ServerStorage.SideRight:Clone()
	Generate.Parent = workspace
	OldPart_CFrame = Generate.Position.Z -- Z Axis
	Generate.CFrame = Generate.CFrame * CFrame.new(0, 0, 19.2 + math.pi+2)
end	
if Choose == 7 then
	local Generate = game.ServerStorage.Slide:Clone()
	Generate.Parent = workspace
	OldPart_CFrame = Generate.Position.Z -- Z Axis
	Generate.CFrame = Generate.CFrame * CFrame.new(0, 0, 19.2 + math.pi+2)
end	
if Choose == 7 then
	local Generate = game.ServerStorage.TopJumps:Clone()
	Generate.Parent = workspace
	OldPart_CFrame = Generate.Position.Z -- Z Axis
	Generate.CFrame = Generate.CFrame * CFrame.new(0, 0, 19.2 + math.pi+2)
end	
end

1 comment

0

No idea what you're trying to do.

1 answer

✓ Accepted answer

Before I give the solution, let me explain to the readers what the OP is trying to do. The OP is trying to position the parts according to the name of the brick randomly chosen. For example, if the "SideLeft" part is chosen, it is positioned to the left side of the previous part and towards the front of the previous brick.

To center a brick:

OldPart.CFrame * CFrame.new()

This is the origin of the cframe of the old part. The CFrame.new() is for any changes you want to make towards any other axis.

To left side a brick:

OldPart.CFrame * CFrame.new((OldPart.Size.X/2) + (NewPart.Size.X/2), 0, 0 )

The emphasis here is the half of the oldpart's size added by the half of the newpart's size.

To right side a brick:

OldPart.CFrame * CFrame.new((-OldPart.Size.X/2) + (NewPart.Size.X/2), 0, 0 )

The emphasis here is the inverse of the half of the oldpart's size added by the half of the newpart's size.

Solution:


local OldPart = workspace.Default

while wait(2) do
   	local Choose = math.random(1,8)
	if Choose == 1 then
		local Generate = game.ServerStorage.Default:Clone()
   		Generate.Parent = workspace
    	Generate.CFrame = OldPart.CFrame * CFrame.new(0, 0, 	Generate.Size.z)
 		OldPart = Generate
	end
	if Choose == 2 then
		local Generate = game.ServerStorage.Jumps:Clone()
   		Generate.Parent = workspace
    	Generate.CFrame = OldPart.CFrame * CFrame.new(0, 0, 	Generate.Size.z)
 		OldPart = Generate
	end
		if Choose == 3 then
		local Generate = game.ServerStorage.Middle:Clone()
   		Generate.Parent = workspace
    	Generate.CFrame = OldPart.CFrame * CFrame.new(0, 0, Generate.Size.z)
		OldPart = Generate
	end
		if Choose == 4 then
		local Generate = game.ServerStorage.NoMiddle:Clone()
   		Generate.Parent = workspace
    	Generate.CFrame = OldPart.CFrame * CFrame.new(0, 0, 	Generate.Size.z)
 		OldPart = Generate
	end
	if Choose == 5 then
		local Generate = game.ServerStorage.SideLeft:Clone()
   		Generate.Parent = workspace
    	Generate.CFrame = OldPart.CFrame * CFrame.new((OldPart.Size.X/2) + Generate.Size.X/2 , 0, 	Generate.Size.z)
 		OldPart = Generate
	end
	if Choose == 6 then
		local Generate = game.ServerStorage.SideRight:Clone()
   		Generate.Parent = workspace
    	Generate.CFrame = OldPart.CFrame * CFrame.new((-OldPart.Size.X/2) + Generate.Size.X/2 , 0, 	Generate.Size.z)
 		OldPart = Generate
	end	
	if Choose == 7 then
		local Generate = game.ServerStorage.Slide:Clone()
   		Generate.Parent = workspace
    	Generate.CFrame = OldPart.CFrame * CFrame.new(0, 0, 	Generate.Size.z)
 		OldPart = Generate
	end	
	if Choose == 7 then
		local Generate = game.ServerStorage.TopJumps:Clone()
   		Generate.Parent = workspace
    	Generate.CFrame = OldPart.CFrame * CFrame.new(0, 0, 	Generate.Size.z)
 		OldPart = Generate
	end	
end

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