Skip to content
The Chat Archive
o1-preview-2024-09-12· OpenAI WildChat-4.8M (AI2)

modifique esse script que ao inves de usar o TextButton, use o mesmo imagebutton Toggle…

  1. User

    modifique esse script que ao inves de usar o TextButton, use o mesmo imagebutton Toggle : local Utility = {}

    --// services local TweenService = game:GetService('TweenService')

    --// variables local AnimationFrame = script.Parent.Parent.MainFrame local ToggleButton = AnimationFrame.Parent.toggle local Player = game.Players.LocalPlayer local scroll = script.Parent.Parent.MainFrame.Content.ScrollingFrame

    -- Tween local function tween(obj, assignedProperty, assignedValue, completeTime, easingStyle, easingDirection) TweenService:Create(obj, TweenInfo.new(completeTime, easingStyle or Enum.EasingStyle.Quint, easingDirection or Enum.EasingDirection.Out), { [assignedProperty] = assignedValue }):Play() end Utility.Tween = tween

    -- Utility.SetupSectionButton() local SelectedSectionButton = nil function Utility.SetupSectionButton(sectionButton, sectionName) sectionButton.MouseButton1Up:Connect(function() Utility.DisableSectionButtons(sectionButton) SelectedSectionButton = sectionButton tween(sectionButton, 'BackgroundColor3', Color3.fromRGB(255,255,255), 0.5) tween(sectionButton, 'BackgroundTransparency', 0.3, 0.5) tween(sectionButton, 'TextColor3', Color3.fromRGB(0,0,0), 0.5) Utility.Query(sectionName) end) sectionButton.MouseEnter:Connect(function() if SelectedSectionButton ~= sectionButton then tween(sectionButton, 'BackgroundColor3', Color3.fromRGB(30,30,30), 0.5) end end) sectionButton.MouseLeave:Connect(function() if SelectedSectionButton ~= sectionButton then tween(sectionButton, 'BackgroundColor3', Color3.fromRGB(10,10,10), 0.5) end end) end

    -- Utility.DisableSectionButtons function Utility.DisableSectionButtons(exception) for i,v in pairs(AnimationFrame.Sections:GetChildren()) do if v:IsA('TextButton') and v ~= exception then tween(v, 'BackgroundColor3', Color3.fromRGB(10,10,10), 0.5) tween(v, 'BackgroundTransparency', 0.7, 0.5) tween(v, 'TextColor3', Color3.fromRGB(255,255,255), 0.5) end end end

    -- Utility.SetRunningAnimation() local SelectedButton = nil local PlayingAnimation = nil function Utility.SetRunningAnimation(button) if SelectedButton then tween(SelectedButton, 'BackgroundColor3', Color3.fromRGB(10, 10, 10), 0.5) tween(SelectedButton, 'BackgroundTransparency', 0.7, 0.5) if SelectedButton == button then if PlayingAnimation then PlayingAnimation:Stop() end SelectedButton = nil PlayingAnimation = nil return end end SelectedButton = button tween(SelectedButton, 'BackgroundColor3', Color3.fromRGB(255,255,255), 0.5) tween(SelectedButton, 'BackgroundTransparency', 0.7, 0.5) if PlayingAnimation then -- stop the running animation PlayingAnimation:Stop() end -- load new animation PlayingAnimation = Player.Character.Humanoid.Animator:LoadAnimation(button.WorldModel.Animation) -- Set the animation priority to "Action" PlayingAnimation.Priority = Enum.AnimationPriority.Action PlayingAnimation:Play() end

    -- Utility.SetupNewButton() function Utility.SetupNewButton(newButton) newButton.MouseEnter:Connect(function() if SelectedButton ~= newButton then tween(newButton, 'BackgroundColor3', Color3.fromRGB(100, 100, 100), 0.5) end end) newButton.MouseLeave:Connect(function() if SelectedButton ~= newButton then tween(newButton, 'BackgroundColor3', Color3.fromRGB(0,0,0), 0.5) end end) end

    -- Utility.Query() function Utility.Query(text) for i, v in pairs(AnimationFrame.Content.ScrollingFrame:GetChildren()) do if v:IsA('ViewportFrame') then v.Visible = (not text and true) or string.find(v:GetAttribute('Section'):lower(), text:lower()) end end end

    -- Utility.EnableToggleButton function Utility.EnableToggleButton() scroll.Visible = true end

    function Utility.DisableToggleButton() scroll.Visible = false end

    return Utility

  2. Assistant

    Sure! I've modified your script to use ImageButton instead of TextButton, as per your request. The main changes involve replacing references to TextButton with ImageButton and adjusting properties that are specific to TextButton. Here's the updated script:

    local Utility = {}
    
    --// Services
    local TweenService = game:GetService('TweenService')
    
    --// Variables
    local AnimationFrame = script.Parent.Parent.MainFrame
    local ToggleButton = AnimationFrame.Parent.toggle -- Assuming 'toggle' is an ImageButton
    local Player = game.Players.LocalPlayer
    local scroll = script.Parent.Parent.MainFrame.Content.ScrollingFrame
    
    -- Tween Function
    local function tween(obj, assignedProperty, assignedValue, completeTime, easingStyle, easingDirection)
        TweenService:Create(obj, TweenInfo.new(completeTime, easingStyle or Enum.EasingStyle.Quint, easingDirection or Enum.EasingDirection.Out), {
            [assignedProperty] = assignedValue
        }):Play()
    end
    Utility.Tween = tween
    
    -- Utility.SetupSectionButton()
    local SelectedSectionButton = nil
    function Utility.SetupSectionButton(sectionButton, sectionName)
        sectionButton.MouseButton1Up:Connect(function()
            Utility.DisableSectionButtons(sectionButton)
            SelectedSectionButton = sectionButton
            tween(sectionButton, 'BackgroundColor3', Color3.fromRGB(255, 255, 255), 0.5)
            tween(sectionButton, 'BackgroundTransparency', 0.3, 0.5)
            -- Since ImageButton doesn't have 'TextColor3', we can change 'ImageColor3' or adjust a child TextLabel if needed
            tween(sectionButton, 'ImageColor3', Color3.fromRGB(0, 0, 0), 0.5)
            Utility.Query(sectionName)
        end)
        sectionButton.MouseEnter:Connect(function()
            if SelectedSectionButton ~= sectionButton then
                tween(sectionButton, 'BackgroundColor3', Color3.fromRGB(30, 30, 30), 0.5)
            end
        end)
        sectionButton.MouseLeave:Connect(function()
            if SelectedSectionButton ~= sectionButton then
                tween(sectionButton, 'BackgroundColor3', Color3.fromRGB(10, 10, 10), 0.5)
            end
        end)
    end
    
    -- Utility.DisableSectionButtons
    function Utility.DisableSectionButtons(exception)
        for i, v in pairs(AnimationFrame.Sections:GetChildren()) do
            if v:IsA('ImageButton') and v ~= exception then
                tween(v, 'BackgroundColor3', Color3.fromRGB(10, 10, 10), 0.5)
                tween(v, 'BackgroundTransparency', 0.7, 0.5)
                tween(v, 'ImageColor3', Color3.fromRGB(255, 255, 255), 0.5)
            end
        end
    end
    
    -- Utility.SetRunningAnimation()
    local SelectedButton = nil
    local PlayingAnimation = nil
    function Utility.SetRunningAnimation(button)
        if SelectedButton then
            tween(SelectedButton, 'BackgroundColor3', Color3.fromRGB(10, 10, 10), 0.5)
            tween(SelectedButton, 'BackgroundTransparency', 0.7, 0.5)
            if SelectedButton == button then
                if PlayingAnimation then
                    PlayingAnimation:Stop()
                end
                SelectedButton = nil
                PlayingAnimation = nil
                return
            end
        end
        SelectedButton = button
        tween(SelectedButton, 'BackgroundColor3', Color3.fromRGB(255, 255, 255), 0.5)
        tween(SelectedButton, 'BackgroundTransparency', 0.7, 0.5)
        if PlayingAnimation then
            PlayingAnimation:Stop()
        end
        -- Load new animation
        PlayingAnimation = Player.Character.Humanoid.Animator:LoadAnimation(button.WorldModel.Animation)
        -- Set the animation priority to "Action"
        PlayingAnimation.Priority = Enum.AnimationPriority.Action
        PlayingAnimation:Play()
    end
    
    -- Utility.SetupNewButton()
    function Utility.SetupNewButton(newButton)
        newButton.MouseEnter:Connect(function()
            if SelectedButton ~= newButton then
                tween(newButton, 'BackgroundColor3', Color3.fromRGB(100, 100, 100), 0.5)
            end
        end)
        newButton.MouseLeave:Connect(function()
            if SelectedButton ~= newButton then
                tween(newButton, 'BackgroundColor3', Color3.fromRGB(0, 0, 0), 0.5)
            end
        end)
    end
    
    -- Utility.Query()
    function Utility.Query(text)
        for i, v in pairs(AnimationFrame.Content.ScrollingFrame:GetChildren()) do
            if v:IsA('ViewportFrame') then
                v.Visible = (not text and true) or string.find(v:GetAttribute('Section'):lower(), text:lower())
            end
        end
    end
    
    -- Utility.EnableToggleButton
    function Utility.EnableToggleButton()
        scroll.Visible = true
    end
    
    function Utility.DisableToggleButton()
        scroll.Visible = false
    end
    
    return Utility
    

    Explanation of Changes:

    • Replaced TextButton with ImageButton:

      • Updated all instances where TextButton was referenced, changing it to ImageButton, such as in v:IsA('ImageButton').
    • Adjusted Properties:

      • Since ImageButton does not have a TextColor3 property, I replaced it with ImageColor3, which changes the color of the image.
      • Removed any references to properties that are specific to TextButton and not available in ImageButton.
      • For changing text properties, if your ImageButton has a child TextLabel or TextButton, you can adjust its properties by accessing it through sectionButton.TextLabel or sectionButton:FindFirstChild("TextLabel").
    • Event Connections:

      • Ensured that all event connections (MouseButton1Up, MouseEnter, MouseLeave) are compatible with ImageButton.

    Additional Notes:

    • Adjusting Text Within ImageButton:

      • If your ImageButton contains text as a child element (e.g., a TextLabel), you might need to adjust the script to change the text color or other properties of the child element. For example:
        local textLabel = sectionButton:FindFirstChildOfClass("TextLabel")
        if textLabel then
            tween(textLabel, 'TextColor3', Color3.fromRGB(0, 0, 0), 0.5)
        end
        
      • Insert this code where you need to adjust the text properties.
    • ImageColor3 Effect:

      • The ImageColor3 property tints the image of the ImageButton. This works best if the image is designed to be color-tintable (e.g., white icons that can be tinted with colors). If your images are full-color, changing ImageColor3 might not produce the desired effect.
    • Testing:

      • After implementing the script, test the buttons to ensure that they behave as expected, and adjust the properties or event connections as needed.

    Let me know if you need further assistance or any other modifications!