My game audio is very laggy

  1. What do you want to achieve?
    I want to remove lag from my game.
  2. What is the issue?
    I think it may be because I overused tweenservice in the little lights, becuse every time they turn on, it lags the whole game. Also only the audio is mainly laggy
    What solutions have you tried so far?
    I looked up tweenservice v2 but when I tried that it was really buggy. I would remove the tween from the lights but I want to keep it that way…

this is the script in EVERY of these little lights in the game:

game.Workspace.Game.Variables.EvacLights.Changed:Connect(function()
	if game.Workspace.Game.Variables.EvacLights.Value == true then
		repeat
			script.Parent.Alarm:Play()
			local tweenservice = game:GetService("TweenService")
			tweenservice:Create(script.Parent,TweenInfo.new(0.25,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut,0,false,0), {Transparency = 0}):Play()
			tweenservice:Create(script.Parent.Attachment.PointLight,TweenInfo.new(0.25,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut,0,false,0), {Brightness = 0.25}):Play()
			wait(1.5)
			tweenservice:Create(script.Parent,TweenInfo.new(0.25,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut,0,false,0), {Transparency = 1}):Play()
			tweenservice:Create(script.Parent.Attachment.PointLight,TweenInfo.new(0.25,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut,0,false,0), {Brightness = 0}):Play()
			wait(0.531)
		until game.Workspace.Game.Variables.EvacLights.Value == false
		script.Parent.Alarm:Stop()
	end
end)
if game.Workspace.Game.Variables.EvacLights.Value == true then
		repeat
			script.Parent.Alarm:Play()

It’s not lagging. You simply put the audio inside the repeat loop which causes it to constantly play from the start. Putting it outside of the loop should solve that.

if game.Workspace.Game.Variables.EvacLights.Value == true then
   script.Parent.Alarm:Play()
   repeat
   -- whatever else
1 Like

Maybe that’s because of your computer.

Yeah but it’s supposed to start over every time it repeats

game.Workspace.Game.Variables.EvacLights.Changed:Connect(function()
	if game.Workspace.Game.Variables.EvacLights.Value == true then
		script.Parent.Alarm:Play()
		repeat
			script.Parent.Alarm.TimePosition = 0
			local tweenservice = game:GetService("TweenService")
			tweenservice:Create(script.Parent,TweenInfo.new(0.25,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut,0,false,0), {Transparency = 0}):Play()
			tweenservice:Create(script.Parent.Attachment.PointLight,TweenInfo.new(0.25,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut,0,false,0), {Brightness = 0.25}):Play()
			wait(1.5)
			tweenservice:Create(script.Parent,TweenInfo.new(0.25,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut,0,false,0), {Transparency = 1}):Play()
			tweenservice:Create(script.Parent.Attachment.PointLight,TweenInfo.new(0.25,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut,0,false,0), {Brightness = 0}):Play()
			wait(0.531)
		until game.Workspace.Game.Variables.EvacLights.Value == false
		script.Parent.Alarm:Stop()
	end
end)

I will try this then…

still laggy. I am getting desperate…

Ok so I know what is the issue. I used in every. single. one audio a pitch effect and that was lagging the game. I removed it and now it works just fine.

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