[UNSOLVED] Flicker On, Off; then Random Part

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    As in the title, I want it so a random part would flicker on then off, then moves to the next random part.

  2. What is the issue? Include screenshots / videos if possible!
    All of them just turns on but it doesn’t turn back off, and doesn’t appear as fast.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I couldn’t find anything atm.
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local TweenService = game:GetService("TweenService")
local BarLeft = game.Workspace.BarLeft

local function shuffle(tbl)
	for i = #tbl, 2, -1 do
		local j = math.random(i)
		tbl[i], tbl[j] = tbl[j], tbl[i]
	end
end

local function flicker()
	while game.Workspace.Contestants.IsPlaying do
		local parts = BarLeft:GetChildren()
		shuffle(parts)

		for _, part in ipairs(parts) do
			if tonumber(part.Name) then 
				TweenService:Create(part, TweenInfo.new(0.2), {Color = Color3.fromRGB(0, 0, 0)}):Play()
				task.wait(0.1)
				TweenService:Create(part, TweenInfo.new(0.2), {Color = Color3.fromRGB(255, 255, 255)}):Play()
				task.wait(0.3) 
			end
		end
	end
end 

local function onClicked()
	for _, part in ipairs(BarLeft:GetChildren()) do
		if tonumber(part.Name) then
			TweenService:Create(part, TweenInfo.new(0.2), {Color = Color3.fromRGB(0, 0, 0)}):Play()
		end
	end
	flicker()
end

script.Parent.ClickDetector.MouseClick:Connect(onClicked)

3 Likes

Bump, im still having this issue.

Sorry I did read your title, your post and your script, but I dont quite understand what you are trying to achieve.

Indeed the logic inside the script seems not right. Could you elaborate whats the exact behavior you expect?

I bet anything you desire to achieve can be done in a very different way than your script is doing right now. I just need to understand what you are aiming for

1 Like

This is what I understand you want?:

  1. ClickDetector is activated
  2. A random part is choosen, it will Tween to black (off)
  3. Upon tween is over another random part will be selected and Tweened to White (on)
  4. Upon On-Tween is over it will turn off (tween to black)
  5. Upon Off-Tween is over it will select a new random part and repeat previous steps from 3 to 5 steps

Click detector is active, a random part is chosen it will tween from white to black, then picks another random part and does the same, like a flicker effect.


like this.

Bump, since i’m still trying to figure this out.

Can I see a video of the current behaviour? I just want to make sure I understand your current situation here.

I just re-read the post, I think I found your bug.

Here, you tween them to black first, before tweening them to white.

The task.wait() lines don’t wait as long as the tweens play, meaning the 1st tween is still playing when the 2nd tween starts, and the loop waits an extra .1 seconds before continuing. If you wanted to wait as long as they played, you can do:

local tween = TweenService:Create(part, TweenInfo.new(0.2), {Color = Color3.fromRGB(255, 255, 255)})
tween:Play()
tween.Completed:Wait()
tween = TweenService:Create(part, TweenInfo.new(0.2), {Color = Color3.fromRGB(0, 0, 0)})
tween:Play()
tween.Completed:Wait()
1 Like

Yep! Forgot to add this, seemed to work.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.