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

color3 change in decal?

local one = script.Parent.one
local r = 255
local g = 255
local b = 255
one.MouseButton1Click:connect(function()
	for i = 1,5 do
		r = r - 10
		g = g - 10
		b = b -10
		game.Workspace.test.Decal.Color3 = Color3.new(r,g,b)
		wait(.1)
	end
end)

ok so what I'm trying to do is to make the decal(game.Workspace.test.Decal) gradually fade to black. For some reason whenever I run this script, the Color3 values of the decal become crazy numbers such as 54790,54669,69504. Is there anything wrong with the script? is there a better way to do this?

1 answer

✓ Accepted answer

It's because you need to use Color3.FromRGB(). Without FromRGB you'd need to divide by 255 to get a number from 0 - 255 (the RGB range). FromRGB does this automatically.

-- Use WaitForChild() on children. 
local one = script.Parent:WaitForChild('one')
local decal = workspace:WaitForChild('test'):WaitForChild("Decal")

-- Use MouseButton1Down and 'C'onnect
one.MouseButton1Down:Connect(function()
    for i = 255, 0, -10 do 
		-- fromRGB
		decal.Color3 = Color3.fromRGB(i,i,i)
		wait()
	end
end)

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