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

My disco floor script isn't working and I don't know why, can someone fix it?

Asked by
Stea_my 48
4 years ago

So basically I have a model with a disco floor in it, all the parts inside of it except for one is called "DiscoFloor" the other is called "DiscoScreen", it only is lighting up "DiscoScreen" and I thought it would light up all of them, can someone fix this? Here is my code

local floors = script.Parent:GetChildren()


for _,p in pairs(floors) do
    while true do
        if p:IsA("Part") then
            p.Color = Color3.new(math.random(), math.random(), math.random())
            wait(.5)
    end
    end
    end
0
Not a request site my man EiOooAxea 70 — 4y

3 answers

Log in to vote
1
Answered by 4 years ago

I have a simple but effective way to fix it. 1st, name all the Discop Floor parts with a number at the end. (Part1, Part2, etc.) Place this Folder into game.Workspace and name it 'GameScriptService'. Insert a script into it and name the script 'DiscoFloor'. Type the following:

local num = 1
local color1 = Color3.fromRGB(0, 255, 0)
local color2 = Color3.fromRGB(0, 0, 255)
while true do
    local parts = game.Workspace.DiscoFloor:GetChildren() --change if you need to
    for i = 1,#parts do
        if num == 1 then
            if parts[i].Name == "Part1" or parts[i].Name == "Part3" then --Add more if necessary. This may not be the simplest way to do it, but it's the only way I know right now.
                parts[i].Color = color1
            else
                parts[i].Color = color2
            end
            num = 2
        else
            if parts[i].Name == "Part1" or parts[i].Name == "Part3" then --Add more if necessary.
                parts[i].Color = color2
            else
                parts[i].Color = color1
            end
            num = 1
        end
    end
end

If this doesn't work, let me know and I'll try something else.

0
Doesn't work sadly, I'm getting an error that says: "Script timeout: exhausted allowed execution time" on line 20, any fixes? Stea_my 48 — 4y
0
There isn't any waits in the while loop. you could put a wait() at the end or you could change "while true do" to "while wait() do" NordicM 77 — 4y
0
Ah yes. My bad. Change it to while true do to while wait(1) do - Then it should work. Sorry. JB_SuperGamer 165 — 4y
0
Change 'while true do' to 'while wait(1) do' JB_SuperGamer 165 — 4y
0
Thank you! After I changed "while true do" to "while wait(1) do" it worked, I'm very glad that now my game doesn't have to lag due to lots of scripts! Stea_my 48 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

just rename all "disco floor" into "disco screen"

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

I know what caused your problem. You gave while true do so it will forever go on looping the same brick. The script I gave below will change the color of every part and set it to random color every second.

Just rewrite the whole script as:

while true do
    for _,p in pairs(script.Parent:GetChildren()) do
        if p:IsA("Part") then
            p.Color = BrickColor.random()
        end
    end
    wait(1)
end

I hope that helps :D

0
My script is very simple. Write it in the script and it will work. Shounak123 461 — 4y

Answer this question