local function pcolor()
local x = 0
while true do
Color3.new(Color3.fromHSV(x,1,1))
x = x + 2/255
if x >=1 then
x=0
end
wait()
end
local startColor = pcolor()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local lightModel = workspace.LEDBox
local lights = {
lightModel.LED1.led,
lightModel.LED2.led,
lightModel.LED3.led,
lightModel.LED4.led,
lightModel.LED5.led,
lightModel.LED6.led,
lightModel.LED7.led,
lightModel.LED8.led,
lightModel.LED9.led
}
local x, y, z = math.random(0,1), math.random(0,1), math.random(0,1)
local startColor = Color3.new(x, y, z)
local endColor = Color3.new(0, 0, 0)
local fadeTime = 0.3
local lightAnimations = {}
for _, light in lights do
lightAnimations[light] = TweenService:Create(light, TweenInfo.new(fadeTime),{Color = endColor})
end
function fade(light)
local tween = lightAnimations[light]
if lightAnimations[light] then
if tween.PlaybackState == Enum.PlaybackState.Playing then
tween:Cancel()
end
tween:Play()
end
end
game.ReplicatedStorage.LightStart.OnServerEvent:Connect(function(player, light)
local tween = lightAnimations[light]
if lightAnimations[light] then
if tween.PlaybackState == Enum.PlaybackState.Playing then
tween:Cancel()
end
end
light.Color = startColor
end)
game.ReplicatedStorage.LightStop.OnServerEvent:Connect(function(player, light)
fade(light)
end)
It’s meant to change the part’s color using a key bind, then applying an animation so it fades back to “endColor”
That’s why I want “startColor” to change every time I do press it.
I don’t understand your local X, Y, Z exactly especially if you’re wanting a random color. You only need to call the function once not 3 different math.randoms