So I've tried making my model move upwards slowly by using a clickdetector. I can make it teleport with the MainPart property but that's the best I can do.
button = script.Parent model = script.Parent.Parent.Parent.Gate button.ClickDetector.MouseClick:connect(function() model:MoveTo(Vector3.new(-22.95, 33.3, 148.5)) end)
How would I make it go upwards slowly rather than have it teleport upwards? This sort of works but is far from good. Any help is appreciated.
To do this, you would use the SetPrimaryPartCFrame function of models and the lerp function of cframe, and of course, a handy for loop.
The set primary part cframe function differs from directly setting a model's primary part in the manner that it moves the entire model rather than just the primary part.
Lerp, or linear interpolation is a way of smoothing changing an object's cframe between two points, the basic function of lerping can be summarized here:
local function lerp(a,b,alpha) return a + (b-a) * alpha end
With that said, you can do the following:
button = script.Parent model = script.Parent.Parent.Parent.Gate local pos = Vector3.new(-22.95, 33.3, 148.5) local start = model:GetPrimaryPartCFrame() button.ClickDetector.MouseClick:Connect(function() for a = 0,1,0.05 do local p = cframe.lerp(start,CFrame.new(pos),a) model:SetPrimaryPartCFrame(p) wait() end end)
Hopefully this helped!