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

How to stop an infinite loop after a brick is touched?

I am making a small project where when a player touches a brick, a seed will slowly emerge (become opaque after being transparent). This is the script :

script.Parent.Touched:connect(function()

for i = 1, 0 , -0.01 do 
	game.Workspace.Seed.Transparency = i
	wait() 
	end

end)

I successfully achieved that, but whenever the brick is being touched by a player even a little bit it keeps repeating this same loop. I want it to stop looping after the seed emerges. How do I stop a loop?

Thanks!

EDIT: I used a debounce.

1 comment

1 answer

you need to add in another variable, but I don't know if this line of code will work for you, gonna wing this. youll need to add a touched event to the seed outside the actual script for this to work

local SeedTouched = 0

if script.Parent.Touched==True and SeedTouched==0 then

SeedTouched=1

1 for i = 1, 0 , -0.01 do

2 game.Workspace.Seed.Transparency = i

3 wait()

4 end

end)

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