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

why will my smaller script work but the bigger not?

while I was trying to make a "brain" for a automated true or false game I was working on. I tested out my smaller script for just a simple test.

while true do
	script.Parent.QNA.GUI.Tex.Text = "Test"
end

which succeeded in the test, but then I tried a longer version and it did not.

while true do
	script.Parent.QNA.GUI.Tex.Text = "Test"
	script.parent.Timer.GUI.Tex.Text = "10"
	wait(1)
	script.parent.Timer.GUI.Tex.Text = "09"
	wait(1)
	script.parent.Timer.GUI.Tex.Text = "08"
	wait(1)
	script.parent.Timer.GUI.Tex.Text = "07"
	wait(1)
	script.parent.Timer.GUI.Tex.Text = "06"
	wait(1)
	script.parent.Timer.GUI.Tex.Text = "05"
	wait(1)
	script.parent.Timer.GUI.Tex.Text = "04"
	wait(1)
	script.parent.Timer.GUI.Tex.Text = "03"
	wait(1)
	script.parent.Timer.GUI.Tex.Text = "02"
	wait(1)
	script.parent.Timer.GUI.Tex.Text = "01"
	wait(1)
	script.parent.Timer.GUI.Tex.Text = "00"
	wait(1)
	script.parent.GREEN.CanCollide = true
	script.parent.GREEN.Transparency = "0.5"
end

I just need help on understanding how to fix it and why it isn't working.

1 comment

0

.Parent needs to have a capital p

1 answer

I'm going to stop you right there since using a while loop for what you want to do is inefficient

. What you should use is a for loop.

For loops

Using for i=10,1,-1 will make a loop that will decrement by 1 from 10. Afterwards, you can then change Tex's text to i(which would be the number of times the loop ran. Since it runs 10 times decrementially, the value of i would go 10, 9, 8, etc)

We then add a wait(1), so the value will change every second.

Since Green's Cancollide and transparency doesn't need to be changed 10 times, I put everything in a function so that it will run after the for loop once.


function go()
		for i = 10,1, -1 do
			script.parent.Timer.GUI.Tex.Text = i
			wait(1)
		end
	 script.parent.GREEN.CanCollide = true
	 script.parent.GREEN.Transparency = "0.5"
end

go()

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