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

How can I make it so my Part changes colors in a specific order?

Asked by 4 years ago

Okay so I want my part to change colors in a specific order for example, red, orange, yellow then repeat (red, orange, yellow, red, orange, etc)

local anger = Color3.fromRGB(226,6,18)
local anticipation = Color3.fromRGB(243,144,50)
local joy = Color3.fromRGB(255,204,1)
local trust = Color3.fromRGB(147,194,59)
local fear = Color3.fromRGB(0,150,63)
local surprise = Color3.fromRGB(11,163,210)
local sadness = Color3.fromRGB(42,129,196)
local disgust = Color3.fromRGB(147,115,178)
local emotionCube = script.Parent
local Tool = script.Parent.Parent


function onActivation()
    print("The color is now red")
    -- function onActivation()
        -- print("The color is now orange")
end

Tool.Activated:Connect(onActivation)

What I have done is make it so that onActivation it prints (for now) red. But the problem is I don't know how to get it to detect I've clicked again and then change to a different. I put in comments what I want to happen ( which is obviously wrong but the idea is to show that onActivation again it prints "The color is now orange".

1 answer

Log in to vote
0
Answered by
TGazza 1336 Moderation Voter
4 years ago

try:

local anger = Color3.fromRGB(226,6,18)
local anticipation = Color3.fromRGB(243,144,50)
local joy = Color3.fromRGB(255,204,1)
local trust = Color3.fromRGB(147,194,59)
local fear = Color3.fromRGB(0,150,63)
local surprise = Color3.fromRGB(11,163,210)
local sadness = Color3.fromRGB(42,129,196)
local disgust = Color3.fromRGB(147,115,178)
local emotionCube = script.Parent
local Tool = script.Parent.Parent

local Colors = { --// our colors table
    Red = Color3.fromRGB(255,0,0),
    Orange = Color3.fromRGB(225,128,0),
    Yellow = Color3.fromRGB(255,255,0)
}
local ColorOrder = {"Red","Orange","Yellow"} --// Display in this order!
local Color_Index = 1 --// our index to remember what color we was on, on last activation

function onActivation()
    local Selected_Color = ColorOrder[Color_Index] --// Grab the name of the color
    local Sel_Color3 = Colors[Selected_Color] --// the color3 value of our table

    print("The color is now "..Selected_Color) --// print out the color name..

    Color_Index = Color_Index +1 <= #ColorOrder and Color_Index +1 or 1 --// bump the index down the color line and if it reaches the end loop back to index one
end

Tool.Activated:Connect(onActivation)

you don't need to have the colors in a table/array but its easier to cycle through them when they are with a numbered index (1-3 etc...)

Hope this helps! :)

0
Holy shit thank you so much this is amazing! DoomRaiders4001 7 — 4y
Ad

Answer this question