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

Could somebody help me with fixing this UI script involving tweens?

Asked by 3 years ago

The problem is that the progress bars for the other abilities won't work at all anymore. The one for the special ability works only the first time, but it doesn't reset, and the other ones don't work at all. I literally don't even know what I'm doing wrong. I checked the API references, play-tested a bunch of times, etc. Nothing's worked. I'm not even sure how I should debug this either. What is going on here?

local screenGui = script.Parent.Parent
local player = game:GetService("Players").LocalPlayer

local Events = game:GetService("ReplicatedStorage").RemoteEventsAndFunctions
local SetHUDProgressBar = Events.SetHUDProgressBar
local SpecialAbilityReady = Events.Abilities.SpecialAbilityReady

workspace:WaitForChild(player.Name)

local character = player.Character
local ability1ProgressBar = script.Parent.Ability1.Progress
local ability2ProgressBar = script.Parent.Ability2.Progress
local ability3ProgressBar = script.Parent.Ability3.Progress
local specialAbilityProgressBar = script.Parent.Parent.SpecialAbility.Progress

local progressBars = {ability1ProgressBar, ability2ProgressBar, ability3ProgressBar, specialAbilityProgressBar}


SetHUDProgressBar.OnClientEvent:Connect(function(abilityIndex, progress, animateToProgress, animTime)
    local clampedProgress = math.clamp(progress, 0, 1)

    if abilityIndex == 4 then
        progressBars[abilityIndex].Parent.Label.Text = math.floor((clampedProgress * 100) + 0.5).."%"
    else
        progressBars[abilityIndex].Parent.TextColor3 = Color3.new(0.290196, 0.290196, 0.290196)
    end

    local function callback(didComplete)
        if didComplete then
            if abilityIndex ~= 4 then
                progressBars[abilityIndex].Parent.TextColor3 = Color3.new(1, 1, 1)
            else
                progressBars[abilityIndex].Parent.BackgroundColor = Color3.new(0.129412, 0.129412, 0.129412)
            end
        end
    end

    if animateToProgress == true then
        if abilityIndex == 4 then
            if specialAbilityProgressBar.BackgroundTransparency == 1 then
                specialAbilityProgressBar.BackgroundTransparency = 0.25
            end

            specialAbilityProgressBar.Parent.BackgroundColor3 = Color3.new(0.129412, 0.129412, 0.129412)
        end
        specialAbilityProgressBar:TweenSize(UDim2.new(1,0,clampedProgress,0), Enum.EasingDirection.InOut, Enum.EasingStyle.Linear, animTime, true, callback)
    elseif animateToProgress == false then
        progressBars[abilityIndex].Size = UDim2.new(1,0,clampedProgress,0)
    end
end)

SpecialAbilityReady.OnClientEvent:Connect(function(abilityName, backgroundColor)
    local specialAbilityFrame = specialAbilityProgressBar.Parent
    specialAbilityProgressBar.BackgroundTransparency = 1
    specialAbilityFrame.Label.Text = abilityName
    specialAbilityFrame.BackgroundColor3 = backgroundColor
end)
0
It just won't tween. It'll set the size, it'll even have the callback function fire after, but it won't tween at all acer1102 97 — 3y

2 answers

Log in to vote
0
Answered by
1JBird1 64
3 years ago

I didn’t see a Play() anywhere in the script, I’m guessing that you want to play on line 46 then maybe try doing


specialAbilityProgressBar:TweenSize(UDim2.new(1,0,clampedProgress,0),Enum.EasingDirection.InOut, Enum.EasingStyle.Linear, animTime, true, callback):Play()

on line 46, though i’ve only done tweening on 3D objects so im unsure.

0
When you call any tween operation for a GUI object it automatically plays as soon as it's called acer1102 97 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

So I took a break from this project shortly after I posted this for various reasons, but since I came back to it I worked around it and it now works

Answer this question