What do you want to achieve?
A fix to the door system
What is the issue?
The lerp code is not working and just teleports the part to its destination without animating it
What solutions have you tried so far?
I tried to look on the devfourm but found no one to have the same problom same with youtube
local Part1 = script.Parent["2"].Union
local part2 = script.Parent["2"].Arrow1
local part3 = script.Parent["2"].Logo
local Part4 = script.Parent["2"].MetelPart
local Part5 = script.Parent["2"].Arrow2
local LerpPart = script.Parent.Lerp2
local LerpPart2 = script.Parent["Lerp2.2"]
local LerpPart3 = script.Parent["Lerp2.1"]
local LerpPart4 = script.Parent["Lerp2.3"]
local LerpPart5 = script.Parent["Lerp2.4"]
local InvisUnion = script.Parent.Invis2.Union
local InvisArrow1 = script.Parent.Invis2.Arrow1
local InvisLogo = script.Parent.Invis2.Logo
local InvisMetal = script.Parent.Invis2.MetelPart
local InvisArrow2 = script.Parent.Invis2.Arrow2
Part1.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
for i = 0, 0.5, 0.1 do
task.wait()
print(i)
Part1.CFrame = LerpPart.CFrame:Lerp(LerpPart.CFrame,i)
part2.CFrame = LerpPart2.CFrame:Lerp(LerpPart2.CFrame,i)
part3.CFrame = LerpPart3.CFrame:Lerp(LerpPart3.CFrame,i)
Part4.CFrame = LerpPart4.CFrame:Lerp(LerpPart4.CFrame,i)
Part5.CFrame = LerpPart5.CFrame:Lerp(LerpPart5.CFrame,i)
wait(1)
Part1.CFrame = InvisUnion.CFrame:Lerp(InvisUnion.CFrame,1)
part2.CFrame = InvisArrow1.CFrame:Lerp(InvisArrow1.CFrame,1)
part3.CFrame = InvisLogo.CFrame:Lerp(InvisLogo.CFrame,1)
Part4.CFrame = InvisMetal.CFrame:Lerp(InvisMetal.CFrame,1)
Part5.CFrame = InvisArrow2.CFrame:Lerp(InvisArrow2.CFrame,1)
end
end
end)
There are a couple possible solutions but since you’re giving us so little info it’s hard for me to narrow it down. here are some possible problems I think might be causing this:
The .Touched function fires every single time it’s touched, so it might be firing multiple times at the same time. You can implement a debounce system to solve this:
(Source: https://dev.to/jeremiahjacinth13/what-is-debouncing-1akk, this article is a good read if you need to understand the debounce concept, though the article is about JavaScript, which is a different programming language than Lua, the one roblox uses.)
You might be using the wrong parts in the Lerp function, have you verified that you’re using the right ones?
You might want to take a look at regular Tweens with TweenService:Create() which seems to produce much smoother animations, from what I’ve seen.
You can try to implement each of these one by one and see if it fixes the problem. If not, post more information and we will be able to help you.
The problem you’re experiencing is because everytime the loop runs you’re setting the position to 1 after 1 second passes
Also, you’re starting the loop at 0 then stopping at 0.5 which means that they’l only reach halfway to your target destination
Edit: Just in case, by position I mean the time position of the lerp
Edit2: @LEO0166 Here’s an example you can use to lerp smoothly using deltaTime:
local RunService = game:GetService("RunService")
local speed = 1 -- How many seconds to reach lerp goal
local Part1 = script.Parent["2"].Union
local part2 = script.Parent["2"].Arrow1
local part3 = script.Parent["2"].Logo
local Part4 = script.Parent["2"].MetelPart
local Part5 = script.Parent["2"].Arrow2
local LerpPart = script.Parent.Lerp2
local LerpPart2 = script.Parent["Lerp2.2"]
local LerpPart3 = script.Parent["Lerp2.1"]
local LerpPart4 = script.Parent["Lerp2.3"]
local LerpPart5 = script.Parent["Lerp2.4"]
local InvisUnion = script.Parent.Invis2.Union
local InvisArrow1 = script.Parent.Invis2.Arrow1
local InvisLogo = script.Parent.Invis2.Logo
local InvisMetal = script.Parent.Invis2.MetelPart
local InvisArrow2 = script.Parent.Invis2.Arrow2
speed = 1 / speed
local connection = nil
local i = 0
Part1.Touched:Connect(function(hit)
if connection then return end
if hit.Parent:FindFirstChild("Humanoid") then
connection = RunService.Heartbeat:Connect(function(deltaTime)
i = math.min(i + deltaTime * speed, 1)
Part1.CFrame = LerpPart.CFrame:Lerp(LerpPart.CFrame,i)
part2.CFrame = LerpPart2.CFrame:Lerp(LerpPart2.CFrame,i)
part3.CFrame = LerpPart3.CFrame:Lerp(LerpPart3.CFrame,i)
Part4.CFrame = LerpPart4.CFrame:Lerp(LerpPart4.CFrame,i)
Part5.CFrame = LerpPart5.CFrame:Lerp(LerpPart5.CFrame,i)
if i == 1 then
connection:Disconnect()
connection = nil
end
end)
end
end)
Edit: @LEO0166 I noticed an important detail, this should work now:
local RunService = game:GetService("RunService")
local speed = 1 -- How many seconds to reach lerp goal
local Part1 = script.Parent["2"].Union
local part2 = script.Parent["2"].Arrow1
local part3 = script.Parent["2"].Logo
local Part4 = script.Parent["2"].MetelPart
local Part5 = script.Parent["2"].Arrow2
local LerpPart = script.Parent.Lerp2
local LerpPart2 = script.Parent["Lerp2.2"]
local LerpPart3 = script.Parent["Lerp2.1"]
local LerpPart4 = script.Parent["Lerp2.3"]
local LerpPart5 = script.Parent["Lerp2.4"]
local InvisUnion = script.Parent.Invis2.Union
local InvisArrow1 = script.Parent.Invis2.Arrow1
local InvisLogo = script.Parent.Invis2.Logo
local InvisMetal = script.Parent.Invis2.MetelPart
local InvisArrow2 = script.Parent.Invis2.Arrow2
speed = 1 / speed
local connection = nil
local i = 0
Part1.Touched:Connect(function(hit)
if connection then return end
if hit.Parent:FindFirstChild("Humanoid") then
connection = RunService.Heartbeat:Connect(function(deltaTime)
i = math.min(i + deltaTime * speed, 1)
Part1.CFrame = Part1.CFrame:Lerp(LerpPart.CFrame,i)
part2.CFrame = part2.CFrame:Lerp(LerpPart2.CFrame,i)
part3.CFrame = part3.CFrame:Lerp(LerpPart3.CFrame,i)
Part4.CFrame = Part4.CFrame:Lerp(LerpPart4.CFrame,i)
Part5.CFrame = Part5.CFrame:Lerp(LerpPart5.CFrame,i)
if i == 1 then
connection:Disconnect()
connection = nil
end
end)
end
end)