UIGradient not appearing unless a certain one is loaded

I made a script that enables/disables UI gradients depending on the a value. However, the gradients don’t appear unless a certain one is loaded. I have all of the gradients parented to a frame, and no gradients appear unless the first one is enabled/loaded.

Apologies if something didn’t make sense.

Example:

In studio

image
image

On play

image
image

It’s enabled on play, and in studio, but it doesn’t appear.
It doesn’t just apply to that one gradient, it applies to all others except the first child.

How could I fix this issue? It’s incredibly annoying and makes my game really weird.

I don’t think it’s a loading issue as it doesn’t load no matter how much time I give it.
Thanks!

Could you perhaps provide the script or a sample of the script?

1 Like

I can’t provide the entire thing, but it works somewhat like this:

local frame = script.Parent.Parent.ItemViewport:WaitForChild("Frame")

local function disableOthers()
	for i,v in pairs(frame:GetChildren()) do
		v.Enabled = false
	end
end

script.Parent:GetPropertyChangedSignal("Value"):Connect(function()
	if script.Parent.Value == "test" then
		disableOthers()
		frame:FindFirstChild("UIGradientExample1").Enabled = true
-- and so on with 
	elseif script.Parent.Value == "test2" then
		disableOthers()
		frame:FindFirstChild("UIGradientExample2").Enabled = true
	end
end)

Can you also provide a picture of the explorer so I could see the hierarchy?

1 Like

image

All the random gradients would have different names. They are not script-generated.

SelectedItem is the value with the script.

Ah okay. I’m starting to see the problem. I will send you an updated script soon.

1 Like

I don’t think it’s the script’s issue, as I disabled it and the gradient still didn’t load. I don’t have the time now, but I’ll check if other gradients are working for other frames.

Your script works perfectly fine and I am getting the same problem as you. I tried enabling and disabling it manually in studio and the gradients aren’t changing unless the StringValue is set equal to the first option. I will try to find a work around though.

1 Like

Huh. UIGradients work on other frames. I tried moving the frame out and then back into the ViewportFrame, and the gradients don’t show in studio anymore.

Ah. Found the issue. The UIGradient instantly disappears when multiple UIGradients are placed, even if they are disabled.

I found a work around. I will send you what I have very soon.

1 Like

Weird, I just made the frame again, removed the gradients, inserted them in again and somehow, it works now. What’s your solution?

So what I did was that I just kept one UIGradient and changed the colors whenever the StringValue changes rather than enabling/disabling multiple gradients.

DevForums Color.rbxl (26.1 KB)

3 Likes