Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I need help creating a script that will clone with math?

Asked by 6 years ago

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.

function hit (track)
    local part = game.Workspace.Tracks
local cloned = part:Clone()
cloned.Parent = game.Workspace

    cloned.Position = Vector3.new(-39, 5, -34)
end

script.Parent.Touched:Connect(hit)

if this explanation is hard to read please tell me. Thanks!

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

You can add vectors together using math.

This should produce the result you are looking for:

NewTrack.Position = OldTrack.Position + Vector3.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))

0
I dont understand the use of NewTrack and OldTrack, and where would i implement? guywithapoo 81 — 6y
0
NewTrack = the cloned track. OldTrack = the piece before the cloned track. SummerEquinox 643 — 6y
Ad

Answer this question