Tweening a lot of lights lag

Hello ive been trying to make a horror game and i wanted to make a command that makes all of the lights tween to the color red but for some reason the result is not smooth and i dont know what i could do"
this is my script

game.Players.PlayerAdded:Connect(function(plr)
	if plr.Name == "nikos300" then
		plr.Chatted:Connect(function(msg)
			if msg == "/e troll" then
				task.spawn(function()
					script.Parent:Play()
					script.Parent.Volume = 0
					game:GetService("TweenService"):Create(script.Parent,TweenInfo.new(1,Enum.EasingStyle.Linear),{Volume = 1}):Play()
					game:GetService("TweenService"):Create(game.Lighting,TweenInfo.new(1,Enum.EasingStyle.Linear),{Ambient = Color3.fromRGB(75,0,0)}):Play()
					task.wait(45)
					game:GetService("TweenService"):Create(script.Parent,TweenInfo.new(0.5,Enum.EasingStyle.Linear),{Volume = 0}):Play()
					game:GetService("TweenService"):Create(game.Lighting,TweenInfo.new(1,Enum.EasingStyle.Linear),{Ambient = Color3.fromRGB(75,75,75)}):Play()
					task.wait(0.5)
					script.Parent:Stop()
				end)
				for i,v in pairs(workspace:GetDescendants()) do
					task.spawn(function()
						if v:IsA("Model") and v.Name == "Light" then
							task.spawn(function()
							for i,v in pairs(v:FindFirstChild("Light").SurfaceLight:GetChildren()) do
								if v:IsA("Script") then
									v.Disabled = true
								end
							end
							end)
							local SelectedColor = Color3.fromRGB(220, 0, 0)
							game:GetService("TweenService"):Create(v:FindFirstChild("Light").SurfaceLight,TweenInfo.new(1,Enum.EasingStyle.Linear),{Color = SelectedColor}):Play()
							game:GetService("TweenService"):Create(v:FindFirstChild("Light"),TweenInfo.new(1,Enum.EasingStyle.Linear),{Color = SelectedColor}):Play()
							--v:FindFirstChild("Light").SurfaceLight.Color = Color
							--v.Light.Color = Color
							task.wait(45) 
							local SelectedColor = Color3.fromRGB(230, 225, 61)
							game:GetService("TweenService"):Create(v:FindFirstChild("Light").SurfaceLight,TweenInfo.new(0.5,Enum.EasingStyle.Linear),{Color = SelectedColor}):Play()
							game:GetService("TweenService"):Create(v:FindFirstChild("Light"),TweenInfo.new(0.5,Enum.EasingStyle.Linear),{Color = SelectedColor}):Play()
							--v:FindFirstChild("Light").SurfaceLight.Color = SelectedColor
							--v.Light.Color = SelectedColor
							task.spawn(function()
							for i,v in pairs(v:FindFirstChild("Light").SurfaceLight:GetChildren()) do
								if v:IsA("Script") then
									v.Disabled = false
								end end
						end) end)	 end)  end end end) end end)
2 Likes

Is the scripts parent a Sound?

1 Like

yes the parent of the script is a sound but i dont think it really matters unless it does

I would try to fire a remoteEvent to all clients after the message is sent and change the lights locally rather than on the server. The TweenService doesn’t play as well on the server as the client…

okay thanks i will try that and let you know if it works

1 Like

I suggest you use variables for when you Tween such as this

local TweenService = game:GetService("TweenService")
local info = TweenInfo.new(1,Enum.EasingStyle.Linear,Enum.EasingDirection.In,0,true,0)
TweenService:Create(part, info, {Color = Color3.fromRGB(255, 0, 0)}):Play()

Thanks it worked. Im guessing the reason was that the server couldn’t handle too many tweens

1 Like

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