# How do I shorten this type of code

I’m convinced that a quicker way of writing this exists, and although the method I used does technically work fine with larger applications it becomes extremely tedious but I have always wrote each line individually. I’ve tried looking around for it but have no clue where to start or what I’m really looking for but I’m trying to link two values together.

Ex. This turning into

``````if Door.Orientation.Y == 0 then Door.LinearVelocity.VectorVelocity = Vector3.new(-2,0,0) end
if Door.Orientation.Y == 90 then Door.LinearVelocity.VectorVelocity = Vector3.new(0,0,2) end
if Door.Orientation.Y == 180 then Door.LinearVelocity.VectorVelocity = Vector3.new(2,0,0) end
if Door.Orientation.Y == -90 then Door.LinearVelocity.VectorVelocity = Vector3.new(0,0,-2) end
``````

this (horrible example im aware it doesnt work exactly like this and im missing a lot)

``````0 = Vector3.new(-2,0,0)
90 = Vector3.new(0,0,2)
180 = Vector3.new(2,0,0)
-90 = Vector3.new(0,0,-2)
``````

let me know if I’m being stupid, or if you know what I’m talking about

1 Like

you could try a dictionary

``````local Vectors = {
 = Vector3.new(-2,0,0),
 = Vector3.new(0,0,2),
 = Vector3.new(2,0,0),
[-90] = Vector3.new(0,0,-2)
}

local Orientation = 90

print(Vectors[Orientation])

--> 0, 0, 2
``````
``````local Orientation = Door.Orientation.Y

if Vectors[Orientation] then
Door.LinearVelocity.VectorVelocity = Vectors[Orientation]
end
``````
4 Likes

Thank you. I knew it was to do with a table I just hit a complete blank when trying to find out the method of actually doing it

1 Like

I have a fèéling that CFrames’ trigonometric stuffs will work here:

``````local angle = 90