I am making a skilift and i am stuck with rotating my model upon returning. I tried a some codes but that didnt work. So im looking for some code that can make my lift rotate (in this case 36°/block, see picture)
This is the code i use to make it move. I’m pretty new with Lua so it’s probably messy. The script is placed as a child of my union, the big grey ‘iron’ frame. It is also the PrimaryPart of my model although I am not familiar with it and the use of it.
local part =script.Parent
local b1 = script.Parent.Parent.Parent.b1
local b2 = script.Parent.Parent.Parent.b2
local b3 = script.Parent.Parent.Parent.b3
local b4 = script.Parent.Parent.Parent.b4
local b5 = script.Parent.Parent.Parent.b5
local b6 = script.Parent.Parent.Parent.b6
local f1 = script.Parent.Parent.Parent.f1
local f2 = script.Parent.Parent.Parent.f2
local f3 = script.Parent.Parent.Parent.f3
local f4 = script.Parent.Parent.Parent.f4
local f5 = script.Parent.Parent.Parent.f5
local f6 = script.Parent.Parent.Parent.f6
local bp = part.BodyPosition
part.BodyGyro.CFrame = part.CFrame
while true do
bp.Position = f6.Position
wait(3)
bp.Position = b1.Position
wait(7)
bp.Position = b2.Position
wait(3)
bp.Position = b3.Position
wait(3)
bp.Position = b4.Position
wait(2)
bp.Position = b5.Position
wait(3)
bp.Position = b6.Position
wait(3)
bp.Position = f1.Position
wait(7)
bp.Position = f2.Position
wait(3)
bp.Position = f3.Position
wait(3)
bp.Position = f4.Position
wait(3)
bp.Position = f5.Position
wait(3)
end
Also the other parts of my model are connected to my union with weldconstraints.
The d(1-6) & f(1-6) are just the blocks used in the turns.
A little word of advice here, please use clear variable names and use For Loops instead of making 50 variables or writing the same thing 50 times. Aside from this, try using the tween service to move between each part in a loop like this:
local Tween = game:GetService("TweenService")
local count = #path:GetChildren()
local tweeninfo, tween, current
local previous = path[#path] --last item
local speed = 20
while true do
for index = 1, count do
current = path[index] --path bricks must be named 1, 2, 3, 4...
tweeninfo = TweenInfo.new(
(previous.Position - current.Position).Magnitude * speed,
Enum.EasingStyle.Linear
)
--whatever brick represents the top/tip of the ski lift
--the ski lift has to be welded to this object!
tween = Tween:Create(TopOfSkiLift, tweeninfo, {CFrame = current.CFrame})
tween:Play()
repeat until tween.Completed:Wait() == Enum.PlaybackState.Completed
previous = current
end
end
You can achieve similar results by using Lerp() but this is a bit less complicated
You can also interpolate the values for the BodyGyro and BodyPosition using this, but those aren’t really necessary.