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

Repeat loop not working? (working with BoolValue)

So basically, if my boolvalue is true it'll play the loop which is what I want! Now the problem is.... I have this repeat loop, and I'm trying to make it so that it will keep on Looping UNITL the boolvalue is false. And I sneaked in a boolvalue.Value = false, yet confusingly it KEEPS on looping???

Here is the script:

local boolvalue = script.Parent.Value
local light = game:GetService("Lighting")
local alarm = script.Parent.Parent.alarm
local message = script.Parent.Parent.corevent
local temp = script.Parent.SurfaceGui.Text
while true do
    wait()		

    if temp.Text == "2000°c" then
        script.Parent.Parent.Map.coremachine.coreOverheat.Fire.Enabled = true
        alarm.Looped = true
        boolvalue.Value = true
    end
	if boolvalue.Value == true then
		message:Play()
repeat
			light.Ambient = Color3.new(150/255,0/255,0/255)
            alarm:Play()
            wait(0.2)
            light.Ambient = Color3.new(0/255,0/255,0/255)
            wait(0.9)
            light.Ambient = Color3.new(150/255,0/255,0/255)
			boolvalue.Value = false
until boolvalue.Value == false
		end
		
end

3 answers

✓ Accepted answer
local boolvalue = script.Parent.Value
local light = game:GetService("Lighting")
local alarm = script.Parent.Parent.alarm
local message = script.Parent.Parent.corevent
local temp = script.Parent.SurfaceGui.Text

local function change(v)
	if (v == true) then
		message:Play()
		
        repeat
            light.Ambient = Color3.new(150/255,0/255,0/255)
            alarm:Play()
            wait(0.2)
            light.Ambient = Color3.new(0/255,0/255,0/255)
            wait(0.9)
            light.Ambient = Color3.new(150/255,0/255,0/255)
        until boolvalue.Value == false
    end
end

boolvalue.Changed:Connect(change)
change(boolvalue.Value)

while true do
    wait()      

    if temp.Text == "2000°c" then
        script.Parent.Parent.Map.coremachine.coreOverheat.Fire.Enabled = true
        alarm.Looped = true
        boolvalue.Value = true
	else
		boolvalue.Value = false
		alarm.Looped = false
    end
end

1 comment

0

Ah right nice to see you here again! Thanks for fixing my script earlier! Also if it's fine with you please respond to my comment in the last question you answered, okay thanks!

Put until boolvalue.Value == false somewhere above boolvalue.Value = false see if that helps.

Try using this

local boolvalue = script.Parent.Value
boolvalue = true --an example to set it

if boolvalue == true then
	--run code
	boolvalue = false
end

if boolvalue == false then
	--run code
	boolvalue = true
end

Good Luck!

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