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

For loop doesn't want to run regardless of what I do?

-- This script is stored in ServerScriptService
local ColorFloor = game.Workspace.ColorFloor:WaitForChild("ColorPlate")
local ColorFloorChildren = ColorFloor:GetChildren()

local function ColorChange()
	print("ColorChange() ran")
	for i, v in ipairs(ColorFloor:GetChildren()) do
		print("For loop ran")
		local randomnumber = math.random(1,1)
		print(randomnumber)
		if randomnumber == 1 then
			v.Color = Color3.FromRGB(0, 0, 0)
		elseif randomnumber == 2 then
			v.Color = Color3.FromRGB(255, 255, 255)
		elseif randomnumber == 3 then
			v.Color = Color3.FromRGB(255, 0, 0)
		elseif randomnumber == 4 then
			v.Color = Color3.FromRGB(0, 255, 0)
		elseif randomnumber == 5 then
			v.Color = Color3.FromRGB(0, 0, 255)
		end
	end
end

ColorChange()
  • Maybe the code itself is what is breaking it. But, I'm pretty sure it is some type of logistics that I'm doing wrong. But, regardless my function will run just fine. My first print will print to the console. But, for some reason the for loop doesn't want to run. Hoping someone can see an issue with the code.

1 comment

0

I see its a disco floor type of code They would all just be 1 cause the minimum is 1 and the maximum is 1 so it would all just be completely black, try setting it to (1,5)

1 answer

I ended up fixing my issue by getting rid of WaitForChild()... I don't know why or how this broke my code. But, I'm not going to question it

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