So I made this disco floor script but it keeps on freezing the whole server every time a color changes, I have tried multiple different ways but all turn out the same. Does anyone know the issue, if it is with this script or if it out of my control? Here is the script:
wait(3)
function RandomRainbow(Red, Blue, Yellow, Orange, Green, Purple, White)
local DiscoMain = game.Workspace.DiscoFloor:GetChildren()
while wait(1.5) do
for i, v in pairs(DiscoMain) do
RandomMathe = math.random(1,7)
if RandomMathe == 1 then
v.BrickColor = Red
end
if RandomMathe == 2 then
v.BrickColor = Orange
end
if RandomMathe == 3 then
v.BrickColor = Yellow
end
if RandomMathe == 4 then
v.BrickColor = Green
end
if RandomMathe == 5 then
v.BrickColor = Blue
end
if RandomMathe == 6 then
v.BrickColor = Purple
end
if RandomMathe == 7 then
v.BrickColor = White
end
end
end
end
RandomRainbow(BrickColor.new("Really red"),BrickColor.new("Bright blue"),BrickColor.new("New Yeller"),BrickColor.new("Neon orange"),BrickColor.new("Bright green"),BrickColor.new("Plum"),BrickColor.new("White"))
I don’t see anything wrong with the script but try this one.
local DiscoMain = workspace.DiscoFloor:GetChildren()
local colors = {
"Really red", "Bright blue", "New Yeller", "Neon orange", "Bright green", "Plum", "White"
}
--why lol
for i, v in next, colors do
colors[i] = BrickColor.new(v)
end
wait(3)
while wait(1.5) do
for _, p in next, DiscoMain do
p.BrickColor = colors[math.random(1, #colors)]
end
end
The OP doesn’t want a condition because the disco floor is a… disco floor. i.e. a floor that changes colors, and I’m sure he wants it to change colors indefinitely.
Also, adding a condition for this loop wouldn’t reduce his lag at all considering he’s lagging every time it changes colors, and not from the fact that it’s running indefinitely.
@henberrysodapop I think your PC simply can’t handle it. There’s no way to reduce the lag that it causes you unless you change the colors one at a time slowly, which I doubt you don’t want. If you do want to try it out, use this code.
local WAIT_TIME = 0.25
local colors = {
"Really red",
"Bright blue",
"New Yeller",
"Neon orange",
"Bright green",
"Plum",
"White"
}
while wait(1.5) do
for k, v in pairs(workspace.DiscoFloor:GetChildren()) do
v.BrickColor = BrickColor.new(colors[math.random(#colors)])
wait(WAIT_TIME)
--alternatively you can use wait() for the smallest increment of time
end
end
Otherwise, there isn’t really a way for this to not lag you. This script doesn’t lag me personally but that’s merely because I have a high-end PC. Editing multiple parts in a short time span will lag you no matter what unless you have a decent PC. And even then, too many parts changing will lag anything.