I need to replicate a string on how many times +1 a value has passed

So I want it to 3.5 okay, put the value +1 the value is 0 so if it went 5 times the value will be 5 so when the value hits 5 i want a code to play in the script not overlapping any of the tweens I want it to transparent when it hits 5 and then wait 20 seconds and fade back to 0 again, and set the value back to 0 and so on it’ll be smooth, will it lag the game if the value is like for example like 700 where it was played 700 times with the while wait +1, and played 700 so that’s 700 times it played, will it lag the game at all? And, also for example if I did it like this like uh when the value hit 50, right so I have certain ifs like if it hit 20 do the same thing if it hit 50 do the same thing and then set the value back to 0 and when its 5 again it’ll play the 5 if right, and so on to 50 and reset if this even makes any sense I’m putting too much thought into this honestly…?

Here’s the script:

local TweenService = game:GetService("TweenService")

local part = script.Parent


local tweenInfoColor = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0)

while wait(3.5) do
	
	local randomColor = Color3.fromRGB( math.random(1, 255), math.random(1, 255), math.random(1, 255) ) 
	part.Dance.Value = part.Dance.Value +1
	
	--Dancefloor--
	
	local tween = TweenService:Create(workspace.DanceFloor.DanceTile, tweenInfoColor, {Color = randomColor  })
		tween:Play()
		
	--Everytime when the dancefloor changes color change the transparency to 0.25 back to 0 before it changes the color, don't make it overlap from when
	--the aquarium shows stop it from transparenting then when aquarium fades back in, make it transparent to 0.25 tweened to 0 back again before it
	--changes the color.
	
	if part.Dance.Value == 5 then

		game.Workspace.DanceFloor.DanceTile.Transparency = 0.1
		game.Workspace.DanceFloor.Frames.Union.Transparency = 0.1

		wait(0.1)

		game.Workspace.DanceFloor.DanceTile.Transparency = 0.2
		game.Workspace.DanceFloor.Frames.Union.Transparency = 0.2

		wait(0.1)

		game.Workspace.DanceFloor.DanceTile.Transparency = 0.3
		game.Workspace.DanceFloor.Frames.Union.Transparency = 0.3

		wait(0.1)

		game.Workspace.DanceFloor.DanceTile.Transparency = 0.4
		game.Workspace.DanceFloor.Frames.Union.Transparency = 0.4

		wait(0.1)

		game.Workspace.DanceFloor.DanceTile.Transparency = 0.5
		game.Workspace.DanceFloor.Frames.Union.Transparency = 0.5

		wait(0.1)

		game.Workspace.DanceFloor.DanceTile.Transparency = 0.6
		game.Workspace.DanceFloor.Frames.Union.Transparency = 0.6

		wait(0.1)

		game.Workspace.DanceFloor.DanceTile.Transparency = 0.7
		game.Workspace.DanceFloor.Frames.Union.Transparency = 0.7

		wait(0.1)

		game.Workspace.DanceFloor.DanceTile.Transparency = 0.8
		game.Workspace.DanceFloor.Frames.Union.Transparency = 0.8

		wait(0.1)

		game.Workspace.DanceFloor.DanceTile.Transparency = 0.9
		game.Workspace.DanceFloor.Frames.Union.Transparency = 0.9

		wait(0.1)

		game.Workspace.DanceFloor.DanceTile.Transparency = 1
		game.Workspace.DanceFloor.Frames.Union.Transparency = 1

		game.Workspace.DanceFloor.Base.Base.Transparency = 1

		task.wait(20)

		game.Workspace.DanceFloor.Base.Base.Transparency = 0

		game.Workspace.DanceFloor.DanceTile.Transparency = 0.9
		game.Workspace.DanceFloor.Frames.Union.Transparency = 0.9

		wait(0.1)

		game.Workspace.DanceFloor.DanceTile.Transparency = 0.8
		game.Workspace.DanceFloor.Frames.Union.Transparency = 0.8

		wait(0.1)

		game.Workspace.DanceFloor.DanceTile.Transparency = 0.7
		game.Workspace.DanceFloor.Frames.Union.Transparency = 0.7

		wait(0.1)

		game.Workspace.DanceFloor.DanceTile.Transparency = 0.6
		game.Workspace.DanceFloor.Frames.Union.Transparency = 0.6

		wait(0.1)

		game.Workspace.DanceFloor.DanceTile.Transparency = 0.5
		game.Workspace.DanceFloor.Frames.Union.Transparency = 0.5

		wait(0.1)

		game.Workspace.DanceFloor.DanceTile.Transparency = 0.4
		game.Workspace.DanceFloor.Frames.Union.Transparency = 0.4

		wait(0.1)

		game.Workspace.DanceFloor.DanceTile.Transparency = 0.3
		game.Workspace.DanceFloor.Frames.Union.Transparency = 0.3

		wait(0.1)

		game.Workspace.DanceFloor.DanceTile.Transparency = 0.2
		game.Workspace.DanceFloor.Frames.Union.Transparency = 0.2

		wait(0.1)

		game.Workspace.DanceFloor.DanceTile.Transparency = 0.1
		game.Workspace.DanceFloor.Frames.Union.Transparency = 0.1

		wait(0.1)

		game.Workspace.DanceFloor.DanceTile.Transparency = 0
		game.Workspace.DanceFloor.Frames.Union.Transparency = 0

		part.Dance.Value = 0
		
		end
	
-----------------------------------------------------------------------------------------------------------------------------------------------------------
	
	-------------------------------------------- Lights ---------------------------------------------------------------------------------
	

	for i, Part in pairs(workspace.DanceFloor.Lights2:GetDescendants()) do
		local Ramp1Tween = TweenService:Create(Part, tweenInfoColor, {Color = randomColor })
		Ramp1Tween:Play()
	end


		
	
	
end


1 Like

PLEASE format your writing, paragraphs are your friend.
Anyway, while I try to figure out what you want to happen, here is a much shorter version of your script lol:

local TweenService = game:GetService("TweenService")

local part = script.Parent


local tweenInfoColor = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0)

while wait(3.5) do

	local randomColor = Color3.fromRGB( math.random(1, 255), math.random(1, 255), math.random(1, 255) ) 
	part.Dance.Value = part.Dance.Value +1

	--Dancefloor--

	local tween = TweenService:Create(workspace.DanceFloor.DanceTile, tweenInfoColor, {Color = randomColor  })
	tween:Play()

	--Everytime when the dancefloor changes color change the transparency to 0.25 back to 0 before it changes the color, don't make it overlap from when
	--the aquarium shows stop it from transparenting then when aquarium fades back in, make it transparent to 0.25 tweened to 0 back again before it
	--changes the color.

	if part.Dance.Value == 5 then
		
		for i = 0.1, 0.9, 0.1 do
			game.Workspace.DanceFloor.DanceTile.Transparency = i
			game.Workspace.DanceFloor.Frames.Union.Transparency = i
			wait(0.1)
		end
		
		game.Workspace.DanceFloor.DanceTile.Transparency = 1
		game.Workspace.DanceFloor.Frames.Union.Transparency = 1
		game.Workspace.DanceFloor.Base.Base.Transparency = 1

		task.wait(20)

		game.Workspace.DanceFloor.Base.Base.Transparency = 0
		
		
		for i = 1, 0, -0.1 do
			game.Workspace.DanceFloor.DanceTile.Transparency = i
			game.Workspace.DanceFloor.Frames.Union.Transparency = i
			wait(0.1)
		end
		part.Dance.Value = 0

	end

	-----------------------------------------------------------------------------------------------------------------------------------------------------------

	-------------------------------------------- Lights ---------------------------------------------------------------------------------


	for i, Part in pairs(workspace.DanceFloor.Lights2:GetDescendants()) do
		local Ramp1Tween = TweenService:Create(Part, tweenInfoColor, {Color = randomColor })
		Ramp1Tween:Play()
	end
end

edit: In answer to your question, provided you don’t call it 700 times at once,, you should have no performance issues

how do i make it so before it changes color i want it to tween to 0.3 back to 0 everytime before it changes the color –

if i want the aquarium to show how would i stop it from transparenting again?

When its supposed to wait 20 seconds do i just do tween:stop() and that specific tween?