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

Test mode in studio stuck at 50%?

I know it must be due to an infinite loop, but I don't know how to fix it. The two only culprits I know it is.

while true do
	script.Parent.Value.Value = 1
	wait(10)
	script.Parent.Value.Value = 2
	wait(10)
	script.Parent.Value.Value = 3
	wait(10)
	script.Parent.Value.Value = 4
	wait(10)
	script.Parent.Value.Value = 5
	wait(10)
end
A = script.Parent.Blue:GetChildren()
B = script.Parent.Red:GetChildren()
change = 1

script.Parent.Value.Changed:connect(function()
	print(change)
end)

while true do
	if script.Parent.Value.Value == 1 then
		change = 1
	elseif script.Parent.Value.Value == 2 then
		change = 0.75
	elseif script.Parent.Value.Value == 3 then
		change = 0.5
	elseif script.Parent.Value.Value == 4 then
		change = 0.25
	elseif script.Parent.Value.Value == 5 then
		change = 0.15
	end
end

while true do
	for i,v in pairs(A) do
		v.PointLight.Enabled = true
		v.SurfaceGui.TextLabel.BackgroundTransparency = 0
	end
	for i,v in pairs(B) do
		v.PointLight.Enabled = false
		v.SurfaceGui.TextLabel.BackgroundTransparency = 1	
	end
	wait(change)
	for i,v in pairs(A) do
		v.PointLight.Enabled = false
		v.SurfaceGui.TextLabel.BackgroundTransparency = 1
	end
	for i,v in pairs(B) do
		v.PointLight.Enabled = true
		v.SurfaceGui.TextLabel.BackgroundTransparency = 0	
	end
	wait(change)
end

1 answer

✓ Accepted answer

From lines 9-21, you have not added a delay, i suggest for the most efficient one, you use wait() perhaps between each one or after the condition.

You can do either way, which ether one you want.

A = script.Parent.Blue:GetChildren()
B = script.Parent.Red:GetChildren()
change = 1

script.Parent.Value.Changed:connect(function()
    print(change)
end)

while true do
    if script.Parent.Value.Value == 1 then
        change = 1
    elseif script.Parent.Value.Value == 2 then
        change = 0.75
    elseif script.Parent.Value.Value == 3 then
        change = 0.5
    elseif script.Parent.Value.Value == 4 then
        change = 0.25
    elseif script.Parent.Value.Value == 5 then
        change = 0.15
    end
    wait()
end

or

while true do
    if script.Parent.Value.Value == 1 then
        change = 1
 	wait()
    elseif script.Parent.Value.Value == 2 then
        change = 0.75
 	wait()
    elseif script.Parent.Value.Value == 3 then
        change = 0.5
	 wait()
    elseif script.Parent.Value.Value == 4 then
        change = 0.25
 	wait()
    elseif script.Parent.Value.Value == 5 then
        change = 0.15
	 wait()
    end
end

Hope that helped, feel free to reply if it didn't.

2 comments

0

I wouldn't suggest the latter method of using wait because in the slight chance that none of those conditions are true the loop will crash because no wait() commands will run. It's much simpler and cleaner to just put a wait at the end

0

True, i made a slight mistake, and yes the first option is the best one.

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