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

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

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

✓ Accepted answer

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))

2 comments

0

I dont understand the use of NewTrack and OldTrack, and where would i implement?

0

NewTrack = the cloned track. OldTrack = the piece before the cloned track.

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