What do you want to achieve? hello am new to scripting, and i can’t make my neon part colour change repeatedly
local a = script.Parent.a
local b = script.Parent.b
local c = script.Parent.c
local d = script.Parent.d
local al = a.PointLight
local bl = b.PointLight
local cl = c.PointLight
local dl = d.PointLight
local colors = {red = Color3.fromRGB(255, 0, 0), green = Color3.fromRGB(40, 127, 71),}
local lcolors = { redl = Color3.fromRGB(130, 27, 27), greenl = Color3.fromRGB(0, 170, 0)}
local randomlcolor = math.random(1,lcolors)
local randomcolor = math.random(1,colors)
while true do
a.Color = randomcolor
al.Color = randomlcolor
task.wait(0.1)
b.Color = randomcolor
bl.Color = randomlcolor
task.wait(0.1)
c.Color = randomcolor
cl.Color = randomlcolor
task.wait(0.1)
d.Color = randomcolor
dl.Color = randomlcolor
task.wait(0.1)
end
am trying to make the lights for the part and the part itself change colour there are exactly 4 parts and 4 spot lights, anything that has an l in it it is for the light and am also trying to make it randomly change forever, thanks
local a = script.Parent.a
local b = script.Parent.b
local c = script.Parent.c
local d = script.Parent.d
local al = a.PointLight
local bl = b.PointLight
local cl = c.PointLight
local dl = d.PointLight
local parts = {a,b,c,d}
local lights = {al,bl,cl,dl}
local colors = {Color3.fromRGB(255, 0, 0),Color3.fromRGB(40, 127, 71),}
local lcolors = {Color3.fromRGB(130, 27, 27),Color3.fromRGB(0, 170, 0)}
while true do
for i = 1,#parts do
local part = parts[i]
local light = lights[i]
local randomPartColor = colors[math.random(1,#colors)]
local randomLightColor = lcolors[math.random(1,#lcolors)]
part.Color = randomPartColor
light.Color = randomLightColor
task.wait(0.1)
end
end
local colors = {Color3.fromRGB(255, 0, 0), Color3.fromRGB(40, 127, 71)} -- define colors
local lcolors = {Color3.fromRGB(130, 27, 27), Color3.fromRGB(0, 170, 0)} -- define light colors
-- colors and lcolors are arrays because there is no key defined (i.e. {hello = "world"})
local parts = {script.Parent.a, script.Parent.b, script.Parent.c, script.Parent.d} -- get the parts
local lights = {} -- to be filled
for i,v in parts do -- loop through all the parts (a,b,c,d)
if v:FindFirstChildOfClass("PointLight") then -- if the part has a pointlight
lights[v] = v:FindFirstChildOfClass("PointLight") -- add the light to the lights table
end
end
while true do -- while loop
for i,v in parts do -- loop through parts
local randomColor, randomLightColor = math.random(#colors), math.random(#lcolors) -- get colors
v.Color = randomColor -- assign color
if lights[v] then -- check if a light exists
lights[v].Color = randomLightColor -- assign the light color
end
task.wait(.1) -- wait 0.1s
end
task.wait(.1) -- wait 0.1s
end
This should fix the problem. Be sure to learn from this code so your scripting skills become better! I labeled all the lines so you understand whats going on.
local a = script.Parent.a
local b = script.Parent.b
local c = script.Parent.c
local d = script.Parent.d
local al = a.PointLight
local bl = b.PointLight
local cl = c.PointLight
local dl = d.PointLight
local colors = {
red = Color3.fromRGB(255, 0, 0),
green = Color3.fromRGB(40, 127, 71),
}
local lcolors = {
redl = Color3.fromRGB(130, 27, 27),
greenl = Color3.fromRGB(0, 170, 0)
}
function getRandomColor(colorTable : {}) : Color3
local keys = {}
for key in pairs(colorTable) do
table.insert(keys, key)
end
local randomKey = keys[math.random(1, #keys)]
return colorTable[randomKey]
end
while true do
local randomcolor = getRandomColor(colors)
local randomlcolor = getRandomColor(lcolors)
a.Color = randomcolor
al.Color = randomlcolor
task.wait(0.1)
end
local randomColor, randomLightColor = math.random(#colors), math.random(#lcolors) -- get colors
v.Color = colors[randomColor] -- assign color
if lights[v] then -- check if a light exists
lights[v].Color = lcolors[randomLightColor ] -- assign the light color
end