Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

color3 change in decal?

Asked by 6 years ago
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

Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

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)
Ad

Answer this question