Making Rails After other Rail

  1. What do you want to achieve? Keep it simple and clear!
    So currently i’m working on my new game. When player join there tons of rails add to map one by one, but i can’t clone them next to each other

  2. What is the issue? Include screenshots / videos if possible!
    I can’t clone these rails to each other

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub? I wanted to use primary part and set position of rails spawn

My code:

local Players = game:GetService("Players")
Players.PlayerAdded:Connect((function(player)
	local GameInstances = Instance.new("Folder")
	GameInstances.Parent = player
	GameInstances.Name = "GameInst"
	local TrainVal = Instance.new("ObjectValue")
	TrainVal.Parent = GameInstances
	TrainVal.Name = "PlayerTrain"
	local ObjectFolder = game:GetService("ReplicatedStorage")
	local RailsModel = ObjectFolder:FindFirstChild("Rails")
	local NewRailsModel = RailsModel:Clone()
	local FirstRail = game.Workspace.GameFolder.Rails.FirstRail.PrimaryPart
	NewRailsModel -- Here idk how to set position
end))

Maybe i should make a union of all parts?

Ok so i found a solutions with unions, BUT i’m getting some strange error in output
image
script:

local Players = game:GetService("Players")
Players.PlayerAdded:Connect((function(player)
	local GameInstances = Instance.new("Folder")
	GameInstances.Parent = player
	GameInstances.Name = "GameInst"
	local TrainVal = Instance.new("ObjectValue")
	TrainVal.Parent = GameInstances
	TrainVal.Name = "PlayerTrain"
	local RailCountVal = Instance.new("IntValue")
	RailCountVal.Parent = GameInstances
	RailCountVal.Name = "RailCount"
	
	local ObjectFolder = game:GetService("ReplicatedStorage").ObjectsFolder
	local RailsModel = ObjectFolder.Rails
	local NewRailsModel = RailsModel:Clone()
	local FirstRail = game.Workspace.GameFolder.Rails.FirstRail.PrimaryPart
	local Pos = FirstRail.Position.Z + 10
	NewRailsModel.PrimaryPart.Position = Vector3(1173.72, 27.678, Pos)
end))

Can’t you just use the previous rail’s position and then just add/subtract the length on one axis?

edit: The error is probably because you did Vector3, rather than Vector3.new.

Ugh you mean it will move a first rail each time?

Could you explain what you mean? I meant that when you place a new rail it will take the previous rail’s position and then just add the length of the new rail.

It must looks like that

Yes. It would look like that. I made a post a while ago that sort of explains what I mean in a slightly convoluted manner. The code is pretty bad but the concept is there:

If you use the previous part’s position you can make it so that every axis apart from the one you want to move in stays the same.

It’s a bit other thing i don’t need RAILS to move i need to make more RAILS when train moving and in the start when player join there is some rails spawns

Which was what he basically said
Can’t you just use the previous rail’s position and then just add/subtract the length on one axis?

also that code that you’re making has a flaw, everytime a player joins it will keep creating rails.

Example code on how you can automize the creation

local Pos = CFrame.new() -- Will start at 0,0,0, up to you to change it.
for i=1, 5 do
  local Part = Part:Clone()
  Part.CFrame = Pos*CFrame.new(0,0,Part.Size.Z)
  Pos = Part.CFrame
  Part.Parent = game.Workspace
end
--Will Create 5 Trails as an example.
--The rotation could be wrong so it'll be up to you to modify it.

Not really. It’s exactly the same. Think about how the parts of the infinite road spawn in to begin with. Did you have a look at the code?

part2.Position = Vector3.new(part1.Position.X, part1.Position.Y, part1.Position.Z+part2.Size.Z)

Demonstrating what I mean:

local part = workspace.Part
local pos = part.Position

for var=1,10 do
	wait(1)
	local part_ = part:Clone()
	part_.Position = Vector3.new(pos.X,pos.Y,pos.Z+part_.Size.Z)
	part_.Parent = workspace
	part = part_
	pos = part_.Position
end

Screenshot 2022-04-28 at 16.46.42