Smooth brightness change/pitch

Is there any way to do like a “For [i]” or something to make this easier?

	script.Parent.Parent["Buzzing Light"].PitchShiftSoundEffect.Octave = 1.1
	wait(0.1)
	script.Parent.Parent["Buzzing Light"].PitchShiftSoundEffect.Octave = 1.2
	wait(0.1)
	script.Parent.Parent["Buzzing Light"].PitchShiftSoundEffect.Octave = 1.3
	wait(0.1)
	script.Parent.Parent["Buzzing Light"].PitchShiftSoundEffect.Octave = 1.4
	wait(0.1)
	script.Parent.Parent["Buzzing Light"].PitchShiftSoundEffect.Octave = 1.5
	wait(0.1)
	script.Parent.Parent["Buzzing Light"].PitchShiftSoundEffect.Octave = 1.6
	wait(0.1)
	script.Parent.Parent["Buzzing Light"].PitchShiftSoundEffect.Octave = 1.7
	wait(0.1)
	script.Parent.Parent["Buzzing Light"].PitchShiftSoundEffect.Octave = 1.8
	wait(0.1)
	script.Parent.Parent["Buzzing Light"].PitchShiftSoundEffect.Octave = 1.9
	wait(0.1)
	script.Parent.Parent["Buzzing Light"].PitchShiftSoundEffect.Octave = 2
	wait(0.1)

I also want to do the same with the brightness of a pointlight

Help!

1 Like

You can tween it!

local TS = game:GetServer("TweenService")

local newinfo = TweenInfo.new(
  1, -- how much time does it take to completely change the values
  Enum.EasingStyle.Linear, -- EasingStyle
  Enum.EasingDirection.In, -- EasingDirection
  0, -- how many time it repeats (most use cases 0)
  false, -- reverses?
  0 -- delay
)

local tween = TS:Create(script.Parent.Parent["Buzzing Light"].PitchShiftSoundEffect.Octave, newinfo, {Value = 2}

tween:Play()

1 Like

If you want a for loop this will do, but personally I would go for the TweenService

local pitchShiftSoundEffect = script.Parent.Parent["Buzzing Light"].PitchShiftSoundEffect

for i = 1, 2, 0.1 do
	pitchShiftSoundEffect.Octave = i
	task.wait(0.1)
end
local tweenInfo = TweenInfo.new(1)

TweenService:Create(pitchShiftSoundEffect, tweenInfo, { Octave = 2 })
1 Like

Is there any way to stop this from stoping the whole task and it just moving on?

	for i = 1, 2, 0.1 do
		script.Parent.Attachment["Buzzing Light"].PitchShiftSoundEffect.Octave = i
		wait(0.1)
	end

	for i = 1, 3, 0.1 do
		script.Parent.Attachment.PointLight.Brightness = i
		wait(0.1)
	end

What do you mean? You want to stop the for-loop?

No, the for loop stops the task, is there a way to make it so it doesn’t stop the task, and both for loops happen at the same time instead of one happening, then waiting for it to finish, then the next one happening?

Just use coroutine, or task.spawn(), But like what I said before just use TweenService, this still gets the same effect and it already runs on a separate thread:

local pitchShiftSoundEffect = script.Parent.Attachment["Buzzing Light"].PitchShiftSoundEffect
local PointLight = script.Parent.Attachment.PointLight

TweenService:Create(pitchShiftSoundEffect, TweenInfo.new(1), { Octave = 2 }):Play()
TweenService:Create(pitchShiftSoundEffect, TweenInfo.new(2), { Brightness = 3 }):Play()
1 Like

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