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

Make a part (or meshpart) fade from one color to another?

Asked by 5 years ago

So, I have a scripted button on a morph I made which should make a meshpart on the morph fade from black to a bright red as a test. I have a BoolValue parented to a script, value set to true, and in the script I have this block of code:

    if script.Value == true then
    repeat
    player.Headz.MeshPart.Color3 = Color3.fromRGB(r, g, b)
    r = r + 1
    wait(.1) until player.Headz.MeshPart.Color3 == Color3.fromRGB(255, g, b)
    end
end

however, this script stops working after the initial lines before this block and it appears I've done something wrong. The whole script:

local player = script.Parent.Parent.Parent.Parent.Parent.Parent.Character
local frame = script.Parent.Parent
local button = script.Parent
local r = 25
local g = 27
local b = 29
function One()
    frame.FP.Visible = false
    frame.KK.Visible = false
    frame.SSJ2.Visible = false
    frame.SSJ4.Visible = false
    frame.SSJB.Visible = false
    frame.SupSS.Visible = true
    button.TextStrokeTransparency = 1
    button.Text = "Base"

    if script.Value == true then
    repeat
    player.Headz.MeshPart.Color3 = Color3.fromRGB(r, g, b)
    r = r + 1
    wait(.1) until player.Headz.MeshPart.Color3 == Color3.fromRGB(255, g, b)
    end
end

function Two()
    frame.FP.Visible = true
    frame.KK.Visible = true
    frame.SSJ2.Visible = true
    frame.SSJ4.Visible = true
    frame.SSJB.Visible = true
    frame.SupSS.Visible = false
    button.TextStrokeTransparency = .7
    button.Text = "Super Saiyan"
    player.Chest.Middle.SS.Playing = false
    player.Chest.Middle.Aura.SS.Enabled = false
    player.Chest.Middle.Aura.SS2.Enabled = false
    player.Chest.Middle.Aura.SS3.Enabled = false
    wait(1)
    player.Headz.MeshPart.BrickColor = BrickColor.new("Black")
    player.Chest.Middle.Off.Playing = true
    player.Headz.G1.Transparency = 0
    wait(1)
    player.Headz.G1.Transparency = 1
    player.Headz.G2.Transparency = .1
    wait(.1)
    player.Headz.G2.Transparency = 1
    player.Headz.G3.Transparency = .3
    wait(.1)
    player.Headz.G3.Transparency = 1
    player.Headz.G4.Transparency = .5
    wait(.1)
    player.Headz.G4.Transparency = 1
    player.Headz.G5.Transparency = .6
    wait(.1)
    player.Headz.G5.Transparency = 1
    player.Headz.G6.Transparency = .7
    wait(.1)
    player.Headz.G6.Transparency = 1
    player.Headz.G7.Transparency = .9
    wait(.1)
    player.Headz.G7.Transparency = 1
end

local O = true
function onClicked()
    if O == true then
        O = false
        One()

    elseif O == false then
    O = true
    Two()
    end
    end
script.Parent.MouseButton1Down:connect (onClicked)

All of my functions, local variables, and part names are correct, and I've triple checked it now. I don't understand why my color fade script won't work, though, it seems right to me and the script and output show no errors besides the script just overall not working.

1 answer

Log in to vote
0
Answered by
blockmask 374 Moderation Voter
5 years ago

If you want it to fade colors, I recommend using TweenService

local TweenService = game:GetService("TweenService")
local Object = script.Parent

local Info = TweenInfo.new(
    2,--Number Time (Seconds)
    Enum.EasingStyle.Bounce, -- EasingStyle
    Enum.EasingDirection.Out, --EasingDirection
    0, --Repeat Count
    false, --If it revers
    0 --Delay Time
)

local Properties = {
    Color=Color3.fromRGB(255,0,0)
}

TweenService:Create(Object,Info,Properties)

Tweenservice isn't that hard. I'm pretty sure you can take a couple looks at the script and understand what it's doing

Ad

Answer this question