Could somebody help me with fixing this UI script involving tweens?
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?
01 | local screenGui = script.Parent.Parent |
02 | local player = game:GetService( "Players" ).LocalPlayer |
04 | local Events = game:GetService( "ReplicatedStorage" ).RemoteEventsAndFunctions |
05 | local SetHUDProgressBar = Events.SetHUDProgressBar |
06 | local SpecialAbilityReady = Events.Abilities.SpecialAbilityReady |
08 | workspace:WaitForChild(player.Name) |
10 | local character = player.Character |
11 | local ability 1 ProgressBar = script.Parent.Ability 1. Progress |
12 | local ability 2 ProgressBar = script.Parent.Ability 2. Progress |
13 | local ability 3 ProgressBar = script.Parent.Ability 3. Progress |
14 | local specialAbilityProgressBar = script.Parent.Parent.SpecialAbility.Progress |
16 | local progressBars = { ability 1 ProgressBar, ability 2 ProgressBar, ability 3 ProgressBar, specialAbilityProgressBar } |
19 | SetHUDProgressBar.OnClientEvent:Connect( function (abilityIndex, progress, animateToProgress, animTime) |
20 | local clampedProgress = math.clamp(progress, 0 , 1 ) |
22 | if abilityIndex = = 4 then |
23 | progressBars [ abilityIndex ] .Parent.Label.Text = math.floor((clampedProgress * 100 ) + 0.5 ).. "%" |
25 | progressBars [ abilityIndex ] .Parent.TextColor 3 = Color 3. new( 0.290196 , 0.290196 , 0.290196 ) |
28 | local function callback(didComplete) |
30 | if abilityIndex ~ = 4 then |
31 | progressBars [ abilityIndex ] .Parent.TextColor 3 = Color 3. new( 1 , 1 , 1 ) |
33 | progressBars [ abilityIndex ] .Parent.BackgroundColor = Color 3. new( 0.129412 , 0.129412 , 0.129412 ) |
38 | if animateToProgress = = true then |
39 | if abilityIndex = = 4 then |
40 | if specialAbilityProgressBar.BackgroundTransparency = = 1 then |
41 | specialAbilityProgressBar.BackgroundTransparency = 0.25 |
44 | specialAbilityProgressBar.Parent.BackgroundColor 3 = Color 3. new( 0.129412 , 0.129412 , 0.129412 ) |
46 | specialAbilityProgressBar:TweenSize(UDim 2. new( 1 , 0 ,clampedProgress, 0 ), Enum.EasingDirection.InOut, Enum.EasingStyle.Linear, animTime, true , callback) |
47 | elseif animateToProgress = = false then |
48 | progressBars [ abilityIndex ] .Size = UDim 2. new( 1 , 0 ,clampedProgress, 0 ) |
52 | SpecialAbilityReady.OnClientEvent:Connect( function (abilityName, backgroundColor) |
53 | local specialAbilityFrame = specialAbilityProgressBar.Parent |
54 | specialAbilityProgressBar.BackgroundTransparency = 1 |
55 | specialAbilityFrame.Label.Text = abilityName |
56 | specialAbilityFrame.BackgroundColor 3 = backgroundColor |