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

How Do You Play 2 Tweens (That Modify The Same Value) At Once?

Asked by 4 years ago

Well For a while now I have been trying to make a jumping animation for my cube in my Geometry Dash Remake Game and I am trying to tween the x and the y of my cube separately so it can jump realistically but it keeps doing them at separate times

Here is the Script if you want to look:

local RS = game.ReplicatedStorage
local REvent1 = RS.Communication.Remote.Events.JumpCube
local BEvent1 = RS.Communication.Bindble.Events.JumpCube
local TWS = game:GetService("TweenService")
local done = true

function tweenModel(model, info, CF)

end


function JumpCube(ply, JumpHight, Direction)
    if done then
        done = false
        if Direction == nil then
            Direction = 1
        else
            if typeof(Direction) == "number" then
                if Direction > 0 then
                    Direction = 1
                elseif Direction < 0 then
                    Direction = -1
                elseif Direction == 0 then
                    warn("Direction Has To Be a non-0 number")
                end
            else
                warn("Direction is not a number pleas put in a number")
            end
        end

        local Speed = game.ServerStorage.CurrentSpeed
        local cube = workspace:WaitForChild("Cube1")
        local cubePP = cube.PrimaryPart
        local JumpXTweenInfo = TweenInfo.new(2,
            Enum.EasingStyle.Quad,
            Enum.EasingDirection.In,
            0,
            false,
            0)
        local JumpYTweenInfo = TweenInfo.new(4,
            Enum.EasingStyle.Quart,
            Enum.EasingDirection.In,
            0,
            false,
            0)
        local BRestrictAxis = RS.Communication.Bindble.Functions.RestrictAxis

        local CFrame1Value = Instance.new("CFrameValue")
        CFrame1Value.Value = cube:GetPrimaryPartCFrame()

        CFrame1Value:GetPropertyChangedSignal("Value"):connect(function()
            cube:SetPrimaryPartCFrame(CFrame1Value.Value)
        end)



        local JumpUpXTweenGoals = {
            Value = CFrame.new(0, JumpHight, 0) * cube:GetPrimaryPartCFrame()
        }

        local JumpUpXTween = TWS:Create(CFrame1Value, JumpXTweenInfo, JumpUpXTweenGoals)


        JumpUpXTween.Completed:connect(function()
            CFrame1Value:Destroy()
        end)

        local CFrame2Value = Instance.new("CFrameValue")
        CFrame2Value.Value = cube:GetPrimaryPartCFrame()

        CFrame2Value:GetPropertyChangedSignal("Value"):connect(function()
            cube:SetPrimaryPartCFrame(CFrame2Value.Value)
        end)



        local JumpUpYTweenGoals = {
            Value = CFrame.new(Direction * Speed.Value * 10, 0, 0) * cube:GetPrimaryPartCFrame()
        }

        local JumpUpYTween = TWS:Create(CFrame2Value, JumpYTweenInfo, JumpUpYTweenGoals)


        JumpUpYTween.Completed:connect(function()
            CFrame2Value:Destroy()
        end)
        --local JumpUpTweenGoals = {
        --  CFrame = CFrame.new(BRestrictAxis:Invoke(cube.RealModelPos + Vector3.new(Direction * Speed.Value * 10 / 2, JumpHight, 0))) 
        --}
        JumpUpXTween:Play()
        JumpUpYTween:Play()

        done = true
    end
end

REvent1.OnServerEvent:Connect(JumpCube)
BEvent1.Event:Connect(JumpCube)

In Line 90 - 91 you see:

        JumpUpXTween:Play()
        JumpUpYTween:Play()

but when I play the tweens(there are no errors) they play at different times which ruins the animation! (There is another problem where when the second tween plays (after the first one) it plays at to starting position of the first one)

HELP!!!!

0
Try combining both tweens "Value = CFrame.new(Direction * Speed.Value * 10, Jumphight, 0) * cube:GetPrimaryPartCFrame()" User#30567 0 — 4y
0
i cant because i'm using 2 tween info's to make it look realistic. if i use only one then it will look unrealistic hhhhhhhhhhhjjhh 12 — 4y

Answer this question