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

How to make this script stop repeating itself in this function?

So I made a basic script, but when i go in game, it runs the BrickColor changes, and the transparency but then repeats, it starts from the start how do i make it so at the last command just stop?

script.Parent.Touched:connect(function()
	script.Parent.BrickColor = BrickColor.new("Really red")
	wait(2)
	script.Parent.Transparency = 0.6
	wait(3)
	script.Parent.BrickColor = BrickColor.new("Bright blue")
end)

the last brickcolor change that makes it Bright Blue to just stop - line 6

1 answer

It repeats because the Touched event fires multiple times when something collides with that part. You can add a debounce to fix this.

local debounce = true
script.Parent.Touched:Connect(function()
	if debounce then
		debounce = false
		script.Parent.BrickColor = BrickColor.new("Bright red")
		wait(2)
		script.Parent.Transparency = 0.6
		wait(3)
		script.Parent.BrickColor = BrickColor.new("Bright blue")
		debounce = true --remove this line if you only want it to hapen once
	end
end)

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