Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

1 comment

0

Not a request site my man

3 answers

✓ Accepted answer

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.

5 comments

0

Doesn't work sadly, I'm getting an error that says: "Script timeout: exhausted allowed execution time" on line 20, any fixes?

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"

0

Ah yes. My bad. Change it to while true do to while wait(1) do - Then it should work. Sorry.

0

Change 'while true do' to 'while wait(1) do'

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!

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

1 comment

0

My script is very simple. Write it in the script and it will work.

This discussion is preserved as it was. New answers, comments, and votes are closed.