Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why are these colors behaving so oddly in this test script?

This is more of a question out of sheer curiosity to some really unusual behavior that I noticed. I was working on a very basic GUI to test a few things out when I was working on a few test with equipping things. I was using Colors because I wasn't really in the mood to bother with values and stuff at the time. Here are both scripts.

The actual equipping:

local player = game:GetService("Players").LocalPlayer
local hum = player.Character:WaitForChild("Humanoid")
local potCol = script.Parent.Parent.PotionColor

script.Parent.MouseButton1Click:Connect(function()
	print("Running")
	if player.Character:FindFirstChildWhichIsA("Tool") then
		print("Unequipped")
		hum:UnequipTools()
	else
		print("Equipping")
		print(potCol.BackgroundColor3)
		
		if potCol.BackgroundColor3 == Color3.new(255, 0, 255) then
			print("Equipped pink")
			hum:EquipTool(player.Backpack:FindFirstChild("PinkPotion"))
		else if potCol.BackgroundColor3 == Color3.new(0, 255, 0) then
			print("Equipped green")
			hum:EquipTool(player.Backpack:FindFirstChild("GreenPotion"))
			end
		end
		
	end
end)

And the quick color change script I threw together:

local color = script.Parent

color.MouseButton1Click:Connect(function()
	print("Next!")
	if color.BackgroundColor3 == Color3.new(255, 0, 255) then
		color.BackgroundColor3 = Color3.new(0, 255, 0)
	else
		color.BackgroundColor3 = Color3.new(255, 0, 255)
	end
end)

The first is in a textbutton and the second is in an image button which is already set to (255, 0, 255). So the only issue that I've seen so far is that if you click to equip without touching the imagebutton, It'll go through but the color it finds shows as (1, 0, 1) and it won't equip anything. If you hit the imagebutton at any point it'll proceed to work as normal.

The second unusual thing I found is that after clicking the image button the first time, the button will remain magenta, fair enough since it's probably also reading the color as (1, 0, 1) originally. Then I looked in explorer to double check and was completely lost as to this next one. The image label BackgroundColor3 was set to (65025, 0, 65025) which would change to (0, 65025, 0).

So what is actually going on here? Is this studio just being really weird or some unusual interaction going on that I don't know. As I've said, the script is functioning properly for the most part, the colors are actually showing up properly, its just these couple of things that are really odd to me.

1 answer

✓ Accepted answer

Use Color.fromRGB not Color.new

1 comment

0

Not quite the answer I was looking for but I had a chance this morning to look into it. Thank you anyway.

This discussion is preserved as it was. New answers, comments, and votes are closed.