Hey guys. I have this script here that successfully clones the variable "Tracks" and puts it directly in front of the previous tracks. I was wondering if its possible to use math to add 24 to X position (i figured out the size between the tracks) that would put it directly in front of the cloned one, so when a train crosses over the part that has the ontouched script it, it will clone the tracks again and again, so in theory will go forever.
1 | function hit (track) |
2 | local part = game.Workspace.Tracks |
3 | local cloned = part:Clone() |
4 | cloned.Parent = game.Workspace |
5 |
6 | cloned.Position = Vector 3. new(- 39 , 5 , - 34 ) |
7 | end |
8 |
9 | script.Parent.Touched:Connect(hit) |
if this explanation is hard to read please tell me. Thanks!
You can add vectors together using math.
This should produce the result you are looking for:
1 | NewTrack.Position = OldTrack.Position + Vector 3. new( 24 , 0 , 0 ) |
This works because Position is a Vector3 value. It can be manipulated with math operators (+, -, *, /) in comparison to another Vector3 value.
In effect, the equation above is equal to: NewVector = ((X1 + X2), (Y1 + Y2), (Z1 + Z2))