Script not repeating itself?

I’m trying to make a fully random event generator script and the whole thing works (I checked it with prints) except when it is supposed to run back around to the starting point. The end of the script has the same values as the ones for the timer part (TimerValue.value > 0, ActivatedValue.value == 2 etc) but it doesn’t really work, do you see any bugs?

(here is the script btw, I shortened it to the main part that I think is not working)

local MainValue = script.Parent.Parent.MainValue
local TimeToBreakValue = script.Parent.Parent.TimeToBreak
local ActivatedYesOrNoValue = script.Parent.Parent.ActivatedYesOrNo
local ProxPrompt = script.Parent
local ProxPromptService = game:GetService("ProximityPromptService")
local Light = script.Parent:WaitForChild("Light")

if ActivatedYesOrNoValue.Value == 2 and MainValue.Value == 3 then
	repeat
		TimeToBreakValue.Value = TimeToBreakValue.Value - 1
		task.wait(1)
	until
	TimeToBreakValue.Value == 0
	print("All Clear in Timer IfElse")
end

ProxPrompt.Triggered:Connect(function()
	
	Light.PointLight.Enabled = true
	ProxPrompt.Enabled = false
	HighLightPart.Highlight.Enabled = false
	ActivatedYesOrNoValue.Value = 2
	TimeToBreakValue.Value = 30
	MainValue.Value = 3
	print("All Clear in prompt triggered")
	print(MainValue.Value, TimeToBreakValue.Value, ActivatedYesOrNoValue.Value)
	
end)

I think you left out something by the repeat until.`

repeat
TimeToBreakValue.Value = TimeToBreakValue.Value - 1
task.wait(1)
until` TimeToBreakValue.Value == 0

Anyways I have to go to sleep.

1 Like

I don’t see anything weird in the script. Could you please send the initial and final values (after the first execution of the script) of the variables ActivatedYesOrNoValue and MainValue? I reckon something is interfering with the if condition.

1 Like

Well the there is an other part that checks if the timervalue == 0, mainvalue == 3 and if Activatedvalue == 2 after which it removes 1 from the activatedvalue (2-1 = 1) and then picks a random number from 1-2. But that part works because the proximity prompt does print the correct numbers that are needed to activate the timer IfElse.

Hard to see what you are trying to achieve, looks like a lot of variables to me. What exactly are you doing and send the whole code, hard to debug pieces of code without knowing the calling code or code that is run before or after this code.

1 Like