Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

[SOLVED BY ME] Position-tweening boat model keeps going below the skybox. How can i fix this?

Asked by 4 years ago
Edited 4 years ago
-- Variables
local ts = game:GetService("TweenService")
local Destination = 1
local boat = script.Parent.Parent
-- Vector destinations
local placestogo = {Vector3.new(0.782, -7.5, -116.367), Vector3.new(35.282, -7.5, -82.117), Vector3.new(120.5, -7.5, -53.25)}
-- function to tween the boat
function tweenBoat(goal,thingToDo)
    if thingToDo == "turn" then
        local tweeninfo = TweenInfo.new(8,Enum.EasingStyle.Linear, Enum.EasingDirection.InOut,0,false,0)
        local cframeValue = Instance.new("CFrameValue", script.Parent)
        cframeValue.Value = script.Parent.CFrame
        local tween = ts:Create(cframeValue, tweeninfo, {Value = goal})
        tween:Play()
        cframeValue.Changed:Connect(function()
            script.Parent.Parent:SetPrimaryPartCFrame(cframeValue.Value)
        end)
        tween.Completed:Wait()
        cframeValue:Destroy()
        print("Yay!")
    elseif thingToDo == "move" then
        local tweeninfo = TweenInfo.new(8,Enum.EasingStyle.Linear, Enum.EasingDirection.InOut,0,false,0)
        local vectorlookat = Instance.new("Vector3Value", script.Parent)
        vectorlookat.Value = goal 
        local vectorvalue = Instance.new("Vector3Value", script.Parent)
        vectorvalue.Value = script.Parent.Position
        local tween = ts:Create(vectorvalue, tweeninfo, {Value = goal})
        tween:Play()
        vectorvalue.Changed:Connect(function()
            local positionWithYLeveled = Vector3.new(vectorvalue.Value.X, vectorvalue.Value.Y, vectorvalue.Value.Z)
            script.Parent.Parent:SetPrimaryPartCFrame(CFrame.new(positionWithYLeveled, vectorlookat.Value))  
        end)
        tween.Completed:Wait()
        vectorlookat:Destroy()
        vectorvalue:Destroy()
        if script.Parent.Position.Y ~= -7.5 then
            script.Parent.CFrame = CFrame.new(Vector3.new(script.Parent.Position.X, -7.5, script.Parent.Position.Z), script.Parent.CFrame.LookVector)
        end 
        print("Yay!")
    end
end
-- wait 10
wait(10)

-- loop to iterate over destination points and call the tweenBoat function
while true do
    wait(2)
    tweenBoat(CFrame.new(script.Parent.Position, placestogo[Destination]), "turn")
    wait(2)
    tweenBoat(placestogo[Destination], "move")
    wait(10)
    print("Tween played")
    Destination = Destination + 1
    if Destination == 4 then
        Destination = 1
    end
    print(Destination)
end



So, the boat keeps going under and then returns without its other parts to destination 1 once it reaches destination 3. How can i fix this? I am not sure what is going wrong.

0
code blocks >:C greatneil80 2647 — 4y

Answer this question