Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can i fix this loop not conuting after the text tranparancy = 0?

--//Varibles\\--
local Plr = game.Players.LocalPlayer
local repStorage = game:GetService("ReplicatedStorage")
local RemoteFolder = repStorage:WaitForChild("RemoteEvents")
local UI = Plr:WaitForChild("PlayerGui")
local Gui = UI:WaitForChild("PlrUI")
local Camera = workspace.CurrentCamera
local cams = workspace.Cameras
local CamPart1 = cams.CameraOne
local CamPart2 = cams.CameraTwo
local CamPart3 = cams.CameraThree
local CamPart4 = cams.CameraFour


local function TextRemote()
    repeat wait()
        Gui.Title.TextTransparency = Gui.Title.TextTransparency - 0.01
        Gui.Title.Title.TextTransparency = Gui.Title.Title.TextTransparency - 0.01
        wait(0.01)
	    until Gui.Title.TextTransparency == 0
	
	wait()
	for Num = 0,1,.01 do
		wait()
    Camera.CFrame = CamPart1.CFrame:lerp(CamPart2.CFrame,Num)
    game:GetService("RunService").RenderStepped:Wait()
	end
	wait()
	for Num = 0,1,.01 do
		wait()
    Camera.CFrame = CamPart2.CFrame:lerp(CamPart3.CFrame,Num)
    game:GetService("RunService").RenderStepped:Wait()
	end
	wait()
	for Num = 0,1,.01 do
		wait()
    Camera.CFrame = CamPart3.CFrame:lerp(CamPart4.CFrame,Num)
    game:GetService("RunService").RenderStepped:Wait()
	end
end


RemoteFolder.TextRemote.OnClientEvent:Connect(TextRemote)

1 answer

It probably never reaches that exit condtion bc things like this happend

-- loop x:
-- transparency is 0.011
-- loop x + 1:
-- transparency is 0.001
-- loop x + 2: 
-- transparency is -0.009

as you see it skipped the exit condtion bc it was never zero. thats why you never compare if its equal but what you do is repeat it until the transpansparaceny is below zero

 repeat 
	wait()
	Gui.Title.TextTransparency = Gui.Title.TextTransparency - 0.01
	Gui.Title.Title.TextTransparency = Gui.Title.Title.TextTransparency - 0.01
	--wait(0.01) first of all minimum wait is 0.03 and this is not needed
 until Gui.Title.TextTransparency < 0 -- also properly indent your code isnt this much easier to read?

Also i super recommend you to use TweenService instead of these so much easier and better

This discussion is preserved as it was. New answers, comments, and votes are closed.