UI Gradient wont enable

When the script detects that the player has the beast or quantum rank it wont enable the gradient for some reason.

local OwnerId = script.Parent:WaitForChild("OwnerId")

local Holder = script.Parent:WaitForChild("Holder")

local function addCommaToNum(num)
	
	local formattedNumber = tostring(num)
	
	local length = string.len(formattedNumber)

	local result = ""
	
	local count = 0

	for i = length, 1, -1 do
		
		result = string.sub(formattedNumber, i, i) .. result
		
		count = count + 1

		if count % 3 == 0 and i ~= 1 then
			
			result = "," .. result
			
		end
		
	end

	return result
	
end

local PCRankColors = require(game:GetService("ServerStorage"):WaitForChild("PCRankColors"))

while true do
	
	local plr = game.Players:GetPlayerByUserId(OwnerId.Value)
	
	if plr then
		
		local LowerText = Holder:WaitForChild("LowerText")

		local TopText = Holder:WaitForChild("TopText")

		local BeastGradient = TopText:WaitForChild("BeastGradient")

		local QuantumGradient = TopText:WaitForChild("QuantumGradient")

		LowerText.Text = plr.DisplayName

		TopText.Text = plr.leaderstats:WaitForChild("PC Rank").Value .. " - " .. addCommaToNum(plr.leaderstats:WaitForChild("Score").Value)

		for Rank,Color in pairs(PCRankColors) do
			
			if plr.leaderstats:WaitForChild("PC Rank").Value == Rank then
				
				if Rank == "Beast" or Rank == "Quantum" then
					
					if plr.leaderstats:WaitForChild("PC Rank").Value == "Beast" then

						TopText.TextColor3 = Color[1]

						TopText.BeastGradient.Enabled = true

					elseif plr.leaderstats:WaitForChild("PC Rank").Value == "Quantum" then

						TopText.TextColor3 = Color[1]

						TopText.QuantumGradient.Enabled = true

					end
					
				else
					
					TopText.TextColor3 = Color[1]

					TopText.UIStroke.Color = Color[2]

					if TopText.BeastGradient.Enabled == true then

						TopText.BeastGradient.Enabled = false

					end

					if TopText.QuantumGradient.Enabled == true then

						TopText.QuantumGradient.Enabled = false

					end
					
				end
				
			end

		end
		
	end
	
	task.wait(0.5)
	
end
1 Like

Throw a few print statements in the script to follow the path. Especially stick one down where you flip true to false…

Shouldn’t elseif just be else since that’s the end of the line for those conditions

elseif plr.leaderstats:WaitForChild("PC Rank").Value == "Quantum" then

Also how come you are checking for Beast and Quantum twice. I think you could do without this:

if Rank == "Beast" or Rank == "Quantum" then

cause you already checking that again underneath

Id put all three conditions under one if/end
if PC Rank is Beast…
elseif PC Rank is Quantum…
else its neither…

if plr.leaderstats:WaitForChild("PC Rank").Value == Rank then
				if plr.leaderstats:WaitForChild("PC Rank").Value == "Beast" then
					TopText.TextColor3 = Color[1]
					TopText.BeastGradient.Enabled = true
				elseif plr.leaderstats:WaitForChild("PC Rank").Value == "Quantum" then
					TopText.TextColor3 = Color[1]
					TopText.QuantumGradient.Enabled = true
				else
					TopText.TextColor3 = Color[1]
					TopText.UIStroke.Color = Color[2]
					if TopText.BeastGradient.Enabled == true then
						TopText.BeastGradient.Enabled = false
					end
					if TopText.QuantumGradient.Enabled == true then
						TopText.QuantumGradient.Enabled = false
					end
				end
			end

Your solution worked! The only problem is sometimes it works 100% as intended and sometimes the gradient just doesn’t work.

I’d probably slow down the True Loop. .5 wait is pretty quick. Just a little lag would throw it off…

Or even better ditch the true loop and replace it with a changed event. That way the code will only run when the value changes.

local player = game:GetService("Players").LocalPlayer
local LSRank = player.leaderstats:WaitForChild("PC Rank") :: string
LSRank.Changed:Connect(function()

-- The other code in here
	
end)