Alright, so I’m trying to destroy a semi when it reaches the end point. I have the for loop that makes the semi move, but I’m trying to figure out how to check when the for loop ends.
Code I tried:
wait(0.8)
for i = 0.001,1,0.001 do
local lerpPos = script.Parent.PrimaryPart.CFrame:Lerp(workspace.Part.CFrame,i)
script.Parent:SetPrimaryPartCFrame(lerpPos)
task.wait(0.05)
end
print(‘this is after the loop ended’)
when the loop ends, it’ll go onto everything after the end. Add a line after the end and make it so it destroys the part by doing:
wait(0.8)
for i = 0.001,1,0.001 do
local lerpPos = script.Parent.PrimaryPart.CFrame:Lerp(workspace.Part.CFrame,i)
script.Parent:SetPrimaryPartCFrame(lerpPos)
task.wait(0.05)
end
print(‘this is after the loop ended’)
script.Parent:Destroy()
because it’ll go on for a long time since it waits 0.05. And it’ll repeat for a while since its starting on 0.001 and increasing by 0.001 Do. Should fix it. Make sure to add the part I put above. after the loop
for i = 0.1,1,0.1 do
local lerpPos = script.Parent.PrimaryPart.CFrame:Lerp(workspace.Part.CFrame,i)
script.Parent:SetPrimaryPartCFrame(lerpPos)
task.wait(0.05)
end
wait(0.8)
for i = 0.001,1,0.001 do
local lerpPos = script.Parent.PrimaryPart.CFrame:Lerp(workspace.Part.CFrame,i)
script.Parent:SetPrimaryPartCFrame(lerpPos)
task.wait(0.05)
end
print("this is after the loop ended")
Since you’re looping it 1000 times and a wait 0.05 in between you gotta wait 50 seconds before it prints anything at all
Ok, first. Unanchor everything other than the primary part. next weld everything to the primary part. After that, insert this script into the model. Edit it to your liking:
local TS = game:GetService("TweenService")
local Goals = {
CFrame = CFrame.new(workspace.Endpoint.Position)
}
local Info = TweenInfo.new(10)
local Model = script.Parent
local Tween = TS:Create(Model.PrimaryPart, Info, Goals)
Tween:Play() -- starts
Tween.Completed:Connect(function() -- after its done
Model:Destroy()
end)