Print() doesn't print anything

long story short I wanted to create a repeat until that would count down from a math.random number to 0 and I’d check it by printing the number. The problem is that it isn’t printing anything. Why isn’t it working?
(note: I used this same code for other scripts and in other scripts it prints perfectly fine)

function CountingDown()
	repeat
		TimeToWait.Value -= 1
		print(TimeToWait.Value)
		task.wait(1)
	until
	TimeToWait.Value == 0
	TestRackProxPrompt.Enabled = true
	TestRackHighlight.Enabled = true
end

i’m straight

1 Like

Are you calling the function anywhere in the code? If not, that is why.

2 Likes

I am calling it later down the road (min word limit)

1 Like

First of all, are you even calling the function?

Second of all, can you show a larger snippet of the code? There might be something else happening that isn’t in the function.

Third of all, why don’t you just use a for loop as a countdown? It would probably be way more efficient anyways

3 Likes

Exactly what I was thinking.

Also you are mentioning the math.random() function but I don’t see it anywhere.

Is math.random() the TimeToWait variable?

3 Likes

Alright here are the core components of the script.

function CountingDown()
	repeat
		TimeToWait.Value -= 1
		print(TimeToWait.Value)
		task.wait(1)
	until
	TimeToWait.Value == 0
	TestRackProxPrompt.Enabled = true
	TestRackHighlight.Enabled = true
end

function Uploading()
	if CanStart == true and StartedCycleValue == false then
		TimerValue.Value = math.random(5, 6)
		CanStart = false
		StartedCycleValue = true
		MonitorHighlight.Enabled = true
		MonitorHighlight2.Enabled = false
		local NewScriptCopy = game.ServerStorage.RepeatScript:Clone()
		NewScriptCopy.Parent = game.Workspace.SampleTesting
		if TimerValue.Value == 0 then
			NewScriptCopy:Destroy()
			MonitorProxPrompt.Enabled = false
			MonitorHighlight.Enabled = false
			MonitorHighlight2.Enabled = false
			TimeToWait.Value = math.random(3, 5) --here is the math.random
			HowMany.Value += 1
			print(HowMany.Value) --btw this also doesn't print
			HardReset() --this one is working
			CountingDown() --calling the function here
		end
	end
end

Everything that doesn’t have a comment works

1 Like

What is HowMany???

Also is the TimeToWait a stringvalue or a numbervalue? If its a stringvalue, change it to numbervalue because math.random() returns a number and not a string.

Oh and also if this doesn’t work then change HowMany to a numbervalue aswell.

2 Likes

HowMany is a external value for a Info Gui I created so I won’t have to open the output bar. And its keeping track how many times the Uploading() function repeated itself.
TimeToWait is a number value.
image
HowMany is also a number value.

1 Like

Hmm. Are there any errors in the output though?

After that can you click Run and then do whatever you need to do and then go to wherever you have stored HowMany and TimeToWait and click it. You should see a number if it works or not.

2 Likes

There aren’t any errors related to this script in the output.

1 Like

Can you tell me the 2nd part i wrote?

1 Like

Nothing changes in those 2 values. I don’t really understand whats wrong because there is a exact replica of this code in a different script (changed a bit but core idea is still the same) and it works perfectly fine.

1 Like

Can you show me the ENTIRE code?

2 Likes

Sure.

local Players = game:GetService("Players")
local Teams = game:GetService("Teams")

local ProxPromptService = game:GetService("ProximityPromptService")
local MonitorProxPrompt = script.Parent["ASUS Computer Monitor Screen"].ScriptPart.ProximityPrompt
local MicroscropeProxPrompt = script.Parent.Microscope.ScriptPart.ProximityPrompt
local TestRackProxPrompt = script.Parent["Test Tube Rack"].ScriptPart.ProximityPrompt
local TimerValue = script.Parent.TimerValue
local TimeToWait = script.Parent.TimeToWait
local MonitorHighlight2 = script.Parent["ASUS Computer Monitor Screen"].Highlight1
local MonitorHighlight, MicroscopeHighlight, TestRackHighlight = script.Parent["ASUS Computer Monitor Screen"].Highlight, script.Parent.Microscope.Highlight, script.Parent["Test Tube Rack"].Highlight
local MicroscopeProx2 = script.Parent.Microscope.ScriptPart.ProximityPrompt2
local MonitorProx2 = script.Parent["ASUS Computer Monitor Screen"].ScriptPart.ProximityPrompt2
local PowerValue = game.Workspace.PowerValue -- overall power
local ScriptCopy = game.ServerStorage.RepeatScript:Clone()
local MostValue = script.Parent.CopyScriptFinished
local HowMany = script.Parent.Parent.HowManyTimesUploaded
StartedCycleValue = false
CanStart = false

function HardReset()
	MicroscropeProxPrompt.Enabled = false
	MicroscopeHighlight.Enabled = false
	MicroscopeProx2.Enabled = false
	MonitorProxPrompt.Enabled = false
	MonitorHighlight.Enabled = false
	MonitorHighlight2.Enabled = false
	TestRackProxPrompt.Enabled = false
	TestRackHighlight.Enabled = false
end

function CountingDown()
	repeat
		TimeToWait.Value -= 1
		print(TimeToWait.Value)
		task.wait(1)
	until
	TimeToWait.Value == 0
	TestRackProxPrompt.Enabled = true
	TestRackHighlight.Enabled = true
end

function ThirdStage()
	TestRackProxPrompt.Enabled = false
	TestRackHighlight.Enabled = false
	MicroscopeHighlight.Enabled = false
	MicroscropeProxPrompt.Enabled = false
	MicroscopeProx2.Enabled = false
	MonitorProxPrompt.Enabled = true
	MonitorHighlight.Enabled = true
	MonitorHighlight2.Enabled = false
	MonitorProxPrompt.ActionText = "Upload Data"
	MostValue.Value = 0
	CanStart = true
	StartedCycleValue = false
end

function Uploading()
	if CanStart == true and StartedCycleValue == false then
		TimerValue.Value = math.random(5, 6)
		CanStart = false
		StartedCycleValue = true
		MonitorHighlight.Enabled = true
		MonitorHighlight2.Enabled = false
		local NewScriptCopy = game.ServerStorage.RepeatScript:Clone()
		NewScriptCopy.Parent = game.Workspace.SampleTesting
		if TimerValue.Value == 0 then
			NewScriptCopy:Destroy()
			MonitorProxPrompt.Enabled = false
			MonitorHighlight.Enabled = false
			MonitorHighlight2.Enabled = false
			TimeToWait.Value = math.random(3, 5)
			HowMany.Value += 1
			print(HowMany.Value)
			HardReset()
			CountingDown()
		end
	end
end

ThirdStage()

MonitorProxPrompt.Triggered:Connect(function()
	Uploading()
end)

TestRackProxPrompt.Triggered:Connect(function()
	
	TestRackProxPrompt.Enabled = false
	TestRackHighlight.Enabled = false
	MicroscropeProxPrompt.Enabled = true
	MicroscopeHighlight.Enabled = true
	
end)

MicroscropeProxPrompt.Triggered:Connect(function()
	MicroscropeProxPrompt.Enabled = false
	MicroscopeProx2.Enabled = true
end)

MicroscopeProx2.Triggered:Connect(function()
	
	ThirdStage()
	
end)

yeah I know its quite a bit messy but its still better than what I wrote 5 months ago

1 Like

where is this script placed? could impact it

2 Likes

its inside a folder with all the values (except the HowMany value)

2 Likes

I believe this is because you are setting TimerValue.Value to a random number between 5 and 6, and then if its zero you call CountingDown, except it obviously cannot be zero, since you just set it to a random number between 5 and 6, I think your problem could be solved if you moved the call to CountingDown to be above the if statement.

EDIT: After reading your code I feel it necessary to mention that if anything were attempting to modify the TimerValue.Value, this code would not actually pick up on it since it only checks if TimerValue.Value is zero once, immediately after setting it, if something outside of this script is attempting to modify TimerValue.Value so as to trigger the if statement, you would need to wrap the if statement in a TimerValue.Changed event.

3 Likes

Sorry to be the bearer of bad news but you focused on the wrong value. You were talking about TimerValue but the problem is with TimeToWait Value. And its my fault because I named them so similarly. But still I appreciate your help and your engagement!

2 Likes

Ah, no, I mean you only start counting down TimeToWait if TimerValue is equal to zero, except it can’t be since you just set it to math.random(5,6), so you never call the CountingDown() function, no?

2 Likes

There is a external script that counts down the TimerValue. Its external because I was experimenting with cloning and destroying scripts. And there are other values in this script because I wanted to hook this script up to “Electricity” in a way that there is a external power value that if it is = 1 then the whole place loses power. But it didn’t work out anyways so I just have it running on all the time without checking for power.

2 Likes