Part spawns in the same position

Alright, every time I say something, it should spawn about 5 blocks away. However, if I type something twice, it spawns in the same position. I don’t know how to fix this.
Any help would be appreciated.

script:

	local LastPart = nil
					
					for i = 1, 5, 1  do
						local NP = Part:Clone()
						NP.Parent = game.Workspace
						LastPart = NP
						NP.Position = LastPart.Position + Vector3.new(0, 1 , 0)
						
						if LastPart == nil then
							LastPart = StartPart
						end
                      
					end

By the way, this is only half of the code. Let me know when you need the rest.

1 Like

Here is a picture of the problem:
Classic Baseplate - Roblox Studio (gyazo.com)

please help!

The “1” in the vector3 is set to the Y axis (Height) wich means your part will spawn at the same X and Y axis but in at different height. If you want to change the postion of the part, change the axis of the vector3. For example:

local LastPart = nil
					
					for i = 1, 5, 1  do
						local NP = Part:Clone()
						NP.Parent = game.Workspace
						LastPart = NP
						NP.Position = LastPart.Position + Vector3.new(1, 0 , 0)
						
						if LastPart == nil then
							LastPart = StartPart
						end
                      
					end

No, that’s not the problem. The Y-axis is what I want. However, for example, if I run it again, it spawns 5 again, but in the same position. I want it to spawn at the top of the other part, not in the same position.

Could you send the entire script because I don’t know what StartPart is ?

I’m sure I can help, but could you provide the full code?

You’re setting the last part before adjusting the position to the actual last part, just move the LastPart = NP down a line.

It appears that you clone the same part (which happens to be also set as NP):

local NP = Part:Clone()
NP.Parent = game.Workspace
LastPart = NP

You don’t change the last part, that’s the problem.
Change this line:

if LastPart == nil then
	LastPart = StartPart
end

into:

if LastPart == nil then
	LastPart = Part
end

Also move
if not LastPart then
LastPart = StartPart
end
To the front of the loop

this is the full script:

I changed the part to ‘startpart’ to make it easier to understand.

local TopicsModule = require(script["Topicsmodule"])

local StartPart = game.Workspace:FindFirstChild("StartPart")


game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		char:PivotTo(StartPart.CFrame + Vector3.new(0, 5, 0))

		player.Chatted:Connect(function(Chat)
			for ind, topic in TopicsModule do
				if Chat == string.lower(topic) then
					local LastPart = nil

					for i = 1, 5, 1  do
						local NP = StartPart:Clone()
						NP.Parent = game.Workspace
						LastPart = NP
						NP.Position = LastPart.Position + Vector3.new(0, 1 , 0)

						if LastPart == nil then
							LastPart = StartPart
						end

					end
				end

			end
		end)
	end)
end)

Try the following:

local TopicsModule = require(script["Topicsmodule"])

local StartPart = game.Workspace:FindFirstChild("StartPart")

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		char:PivotTo(StartPart.CFrame + Vector3.new(0, 5, 0))

		player.Chatted:Connect(function(Chat)
			for ind, topic in TopicsModule do
			    
				if Chat == string.lower(topic) then
		
					local LastPart = StartPart

					for i = 1, 5, 1  do
						local NP = LastPart:Clone()
						NP.Parent = game.Workspace
						NP.Position = LastPart.Position + Vector3.new(0, 1 , 0)
                        
                        LastPart = NP
					end
				end

			end
		end)
	end)
end)

If I spawn two or more times, here is a picture of the main problem.

Picture:
Classic Baseplate - Roblox Studio (gyazo.com)

I see, do give me a moment to think then.

It appears that you increment the Y value. Here’s the new code that increments the X value (if that’s what you’re looking for):

local TopicsModule = require(script["Topicsmodule"])

local StartPart = game.Workspace:FindFirstChild("StartPart")

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		char:PivotTo(StartPart.CFrame + Vector3.new(0, 5, 0))

		player.Chatted:Connect(function(Chat)
			for ind, topic in TopicsModule do
			    
				if Chat == string.lower(topic) then
		
					local LastPart = StartPart

					for i = 1, 5, 1  do
						local NP = LastPart:Clone()
						NP.Parent = game.Workspace
						NP.Position = Vector3.new(LastPart.Position.X + 1, LastPart.Position.Y, LastPart.Position.Z)
                        
                        LastPart = NP
					end
				end

			end
		end)
	end)
end)

Now it does this, and I don’t know why.

Classic Baseplate - Roblox Studio (gyazo.com)

I mean, it kind of worked, but I wish I could spawn 5 instead of 1. But whatever, I’ll mark you as a solution. Thank you!

This should work for the loop:

local TopicsModule = require(script["Topicsmodule"])

local StartPart = game.Workspace:FindFirstChild("StartPart")
local Saved_Part = StartPart:Clone()

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		char:PivotTo(StartPart.CFrame + Vector3.new(0, 5, 0))

		player.Chatted:Connect(function(Chat)
			for ind, topic in TopicsModule do
			    
				if Chat == string.lower(topic) then
				    
				    for instance_value = 1, 5, 1 do
    					local NP = Saved_Part:Clone()
    					NP.Parent = game.Workspace
    					NP.Position = Vector3.new(Saved_Part.Position.X + 5, Saved_Part.Position.Y, Saved_Part.Position.Z)
    					
                        Saved_Part = NP
                       end
					end
				end

			end
		end)
	end)
end)
1 Like