Tweening using Tables - Help Needed

Code:

    play.MouseButton1Click:Connect(function()

        local twee = TS:Create(introframe, ti, {Position = opentarget})
        local twee1 = TS:Create(storeframe, ti, {Position = closetarget})
        local twee2 = TS:Create(teamframe, ti, {Position = closetarget})
        local twee3 = TS:Create(infoframe, ti, {Position = closetarget})
        twee:Play()
        twee1:Play()
        twee2:Play()
        twee3:Play()

    end)

    info.MouseButton1Click:Connect(function()
        
        local twee = TS:Create(introframe, ti, {Position = closetarget})
        local twee1 = TS:Create(storeframe, ti, {Position = closetarget})
        local twee2 = TS:Create(teamframe, ti, {Position = closetarget})
        local twee3 = TS:Create(infoframe, ti, {Position = opentarget})
        twee:Play()
        twee1:Play()
        twee2:Play()
        twee3:Play()
        
    end)
    
    team.MouseButton1Click:Connect(function()

        local twee = TS:Create(introframe, ti, {Position = closetarget})
        local twee1 = TS:Create(storeframe, ti, {Position = closetarget})
        local twee2 = TS:Create(teamframe, ti, {Position = opentarget})
        local twee3 = TS:Create(infoframe, ti, {Position = closetarget})
        twee:Play()
        twee1:Play()
        twee2:Play()
        twee3:Play()

    end)
    
    store.MouseButton1Click:Connect(function()

        local twee = TS:Create(introframe, ti, {Position = closetarget})
        local twee1 = TS:Create(storeframe, ti, {Position = opentarget})
        local twee2 = TS:Create(teamframe, ti, {Position = closetarget})
        local twee3 = TS:Create(infoframe, ti, {Position = closetarget})
        twee:Play()
        twee1:Play()
        twee2:Play()
        twee3:Play()

    end)

  1. What do you want to achieve?

In the first section; play.MouseButton1Click:Connect(function() you see that I made the tween for the introframe so that when play is clicked, it will open the introframe, which is a UI. And other 3 UIs will close if they are open. Now, I did the same for the other 3 buttons, if one UI is open, then all the other UIs will close, if they are open.

Now, is there a way so that the other UIs close if one UI is open, and I don’t have to make seperate tweens, so the work gets done with less code?

  1. What is the issue?

I am having issues in creating a table, which consists of tweens. I have no idea on how to create a table consisting of tweens, and then running the tween.

  1. What solutions have you tried so far?

I’ve looked on Youtube, and Google, but couldn’t find any correct answers.

1 Like

When the player clicks on one of the buttons, you could have each one activate a single function that would create and play the necessary Tweens. To make sure that the Position is set to the correct value for each particular Frame, you could have each of the button activation functions send through the values so that the main function would handle the rest automatically. Here’s an example revision that cuts down on the repeated code:

Example revision

local function createTweens(introframeTarget, storeframeTarget, teamframeTarget, infoframeTarget)
    
    local introframeTween = TS:Create(introframe, ti, {Position = introframeTarget})
    local storeframeTween = TS:Create(storeframe, ti, {Position = storeframeTarget})
    local teamframeTween = TS:Create(teamframe, ti, {Position = teamframeTarget})
    local infoframeTween = TS:Create(infoframe, ti, {Position = infoframeTarget})

    introframeTween:Play()
    storeframeTween:Play()
    teamframeTween:Play()
    infoframeTween:Play()
end

play.MouseButton1Click:Connect(function()
    createTweens(opentarget, closetarget, closetarget, closetarget)
end)

info.MouseButton1Click:Connect(function()
    createTweens(closetarget, closetarget, closetarget, opentarget)
end)
    
team.MouseButton1Click:Connect(function()
    createTweens(closetarget, closetarget, opentarget, closetarget)
end)
    
store.MouseButton1Click:Connect(function()
    createTweens(closetarget, opentarget, closetarget, closetarget)
end)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.