Inventory GUI not changing color[RESOLVED]

I have this script that controls the players’ inventory gui. It is supposed to change the color of certain items but it doesn’t. I’ve changed this script so many times so if it looks confusing or you don’t understand what a certain instance is or what it contains just ask and I’ll explain. Here is the script:

local function changecolors()
	local plr = game.Players.LocalPlayer
	local inventoryfolder = plr:WaitForChild("Inventory")
	local particles = inventoryfolder:GetChildren()
	local inv = plr.PlayerGui.ScreenGui.Inventory
	local template = inv.Template

	for i, v in pairs(inventoryfolder:GetChildren()) do
		if inv:FindFirstChild(v.Name) == nil then
			local newtemplate = template:Clone()
			newtemplate.Name = v.Name
			newtemplate.ImageButton.Image = v.Value
			newtemplate.ItemName.Text = v.Name
			if newtemplate.Name == "Blue" then
				print(newtemplate.Name.." changed to blue")
				newtemplate.ImageButton.ImageColor3 = Color3.new(0.3,0.5,1)
			elseif newtemplate.Name == "Red" then
				print(newtemplate.Name.." changed to red")
				newtemplate.ImageButton.ImageColor3 = Color3.new(0.8,0,0)
			elseif newtemplate.Name == "Pink" then
				print(newtemplate.Name.." changed to pink")
				newtemplate.ImageButton.ImageColor3 = Color3.new(1,0.7,1)
			elseif newtemplate.Name == "Void" then
				print(newtemplate.Name.." changed to black")
				newtemplate.ImageButton.ImageColor3 = Color3.new(0,0,0)
			elseif newtemplate.Name == "USA Fireworks" then
				local colors = {Color3.new(1,0,0), Color3.new(1,1,1), Color3.new(0,0.15,1)}
				while true do
					for i, v in pairs(colors) do
						newtemplate.ImageButton.ImageColor3 = v
						print("Color changed")
						wait(.5)
					end
				end
			end
			newtemplate.Visible = true
			newtemplate.Parent = inv
			print(newtemplate.Name)
			
		else
			--Still working on this ignore lol
			print(v.Name.." Is in the player's inventory folder")
			if v.Name == "Blue" then
				print(v.Name.." changed to blue")
				inv.v.ImageButton.ImageColor3 = Color3.new(0.3,0.5,1)
			elseif v.Name == "Red" then
				print(v.Name.." changed to red")
				inv.v.ImageButton.ImageColor3 = Color3.new(0.8,0,0)
			elseif v.Name == "Pink" then
				print(v.Name.." changed to pink")
				inv.v.ImageButton.ImageColor3 = Color3.new(1,0.7,1)
			elseif v.Name == "Void" then
				print(v.Name.." changed to black")
				inv:FindFirstChild(v).ImageButton.ImageColor3 = Color3.new(0,0,0)
			elseif v.Name == "USA Fireworks" then
				local colors = {Color3.new(1,0,0), Color3.new(1,1,1), Color3.new(0,0.15,1)}
				while true do
					for i, thecolor in pairs(colors) do
						inv.v.ImageButton.ImageColor3 = thecolor
						print("Color changed")
						wait(.5)
					end
				end
			end
			
		end
	end
end
game.ReplicatedStorage.InventoryLoaded.OnClientEvent:Connect(function(plr)
	changecolors()
end)

game.Players.LocalPlayer.CharacterAdded:Connect(function()
	changecolors()
end)

This is my first topic on here, hopefully it’s straightforward and someone can help me figure this out.

What exactly and what doesn’t the script prints?

The only thing the script prints is the “Color changed” in the while loop, yet the color doesn’t actually change in my gui. Also I own every effect listed when I check my inventory in the explorer, and all the icons appear in my inventory gui frame, they just don’t change color.

You are changing ImageColor3 Maybe try BackgroundColor3 and tell if it works?

I think there is a problem in Studio or something try using it in game

This might seem like an odd question but this is part of an update I’m not ready to release publicly, so is there a way I could test it without publishing it? Or making a copy of the game somehow? I’m sorry if this is a super well known feature that I don’t know about :confused:

Just to clarify: is this the default Roblox inventory or a custom inventory that you made?

A custom inventory, not the one used for tools.

1 Like

Hello, I am almost sure that you are storing the colors wrong in this table, try something like:

local colors = {
color1 = {
	1, 0, 0
};
color2 = {
	1, 1, 1
};
color3 = {
	0, 0.15, 1
}

}

while true do
for i, thecolor in pairs(colors) do
inv.v.ImageButton.ImageColor3 = Color3.new(thecolor[1], thecolor[2], thecolor[3])
wait(.5)
end
end

I just tried this method using newtemplate.ImageButton when the template is cloned and inv.v.Image button when the gui already exists in the frame. I’m not sure which one is running but it’s still printing “Color changed” without actually changing the color of the gui

Not sure whether to reply again or edit my previous reply but I actually added this line in the loop:

print(newtemplate.ImageButton.ImageColor3)

and interestingly enough it prints the different colors, yet I don’t see any visual difference in the gui. Any ideas on what could be happening?

Are you sure there is nothing overlapping the image or if the image itself is not visible?

I’m pretty sure. Here is a recording of what my GUI looks like in-game. robloxapp-20200630-1300571.wmv (2.5 MB)

Also, i would use Color3.fromRGB to change the ImageColor3

Add a spawn(function() here…

The spawn function can be added whenever you use a while loop to ensure the rest of the code can still run. Not sure if this will help your entire situation, but it’s worth a try.

Well I can say for sure it is changing colors now. I did not know the spawn function even existed so I’ll look into it more. Thank you so much! :+1:

1 Like

You should use coroutines rather than spawn.

Coroutines are faster, while spawn wait()s before execution.

Example usage:

local corou = coroutine.create(function()
   print("Hello World")
end)
coroutine.resume(corou)

Or you could do:

function aprint(text)
   print(text)
end
coroutine.wrap(aprint)("Hello World")

In my experience, coroutines are faster and have much more uses than the standard spawn.

Also not too familiar with coroutines, but I’ll certainly look into them. Thanks for letting me know about these things!