Quantcast

Tween working for one part but not for other parts?

I took a pulsing light script and implemented it into EventScript.
I make 3 parts pulse but when I test, only one part pulses.
aaaaa help ;-;

Well how are we meant to do anything about it when you don’t even like show the code?

1 Like

yes what Aspa said send script

spawn(function()
		tween:pulsePart(script.Parent.hardwarepulse.one,Color3.fromRGB(4, 175, 236),0.5,1,Color3.fromRGB(27, 42, 53),1.1)
		tween:pulsePart(script.Parent.hardwarepulse.two,Color3.fromRGB(4, 175, 236),0.5,1,Color3.fromRGB(27, 42, 53),1.1)
		tween:pulsePart(script.Parent.hardwarepulse.three,Color3.fromRGB(4, 175, 236),0.5,1,Color3.fromRGB(27, 42, 53),1.1)
end)

The Tween thing is a module.

function tweenModule:pulsePart(part,startcolor,timeafterstartcolor,pulseTime,pulsecolor,timeafterpulsecolor)
	while true do
		part.Color = startcolor
		wait(timeafterstartcolor)
		game:GetService("TweenService"):Create(
			part,TweenInfo.new(pulseTime,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut),
		{Color = pulsecolor}):Play()
		wait(timeafterpulsecolor)
	end
end

New alt, since my iPad is dead.
The reason it won’t pulse all 3, is because the while loop yields. So you have to use spawn(), there are 2 ways to do this:

#1

function tweenModule:pulsePart(part,startcolor,timeafterstartcolor,pulseTime,pulsecolor,timeafterpulsecolor)
    spawn(function()
        while true do
		    part.Color = startcolor
		    wait(timeafterstartcolor)
		    game:GetService("TweenService"):Create(
			part,TweenInfo.new(pulseTime,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut),
		    {Color = pulsecolor}):Play()
		    wait(timeafterpulsecolor)
          end
      end)
end

#2:

spawn(function()
		spawn(function()
            tween:pulsePart(script.Parent.hardwarepulse.one,Color3.fromRGB(4, 175, 236),0.5,1,Color3.fromRGB(27, 42, 53),1.1)
        end)
        spawn(function()
            tween:pulsePart(script.Parent.hardwarepulse.two,Color3.fromRGB(4, 175, 236),0.5,1,Color3.fromRGB(27, 42, 53),1.1)
        end)
        spawn(function()
            tween:pulsePart(script.Parent.hardwarepulse.three,Color3.fromRGB(4, 175, 236),0.5,1,Color3.fromRGB(27, 42, 53),1.1)
        end)
end)

Option 1, makes the whole tween in a spawn, while option 2, each tween is done in a spawn.