Newbie Question- DrawText not vanishing, stays on screen until server rejoin.

Basically I’ve got this bit of code that makes some simple text scroll across the screen. I’ve tried this before with simple DrawText and it just stays there.
I use the code inside a net.Receive.

Here is the DrawText code.


surface.CreateFont( "ScoreboardText", {
	font = "Colaborate-Regular",
	size = 55,
	weight = 500,
	antialias = true,
	shadow = true,
} )

local multiplier = 120			-- greater multiplier = faster scroll
local width = ScrW() 			-- the width of hte space which the text will scroll across
local ypos = 500				-- the y pos on the screen, assuming the text scrolls horizontally
local text = "Hello, World!" 	-- the text to draw
local font = "ScoreboardText"	-- the font to draw it in
local textcol = color_white		-- the color to draw the font

net.Receive( "test", function( len, ply )
	print( "I got it!" )
	hook.Add("HUDPaint","DrawScrollText",function()
	draw.DrawText(text,font,math.fmod(SysTime() * multiplier,width),ypos,textcol,0)
end)
end )

This is the serverside file for the net library shit


	
	if(TotalXP>=self:getMaxXP()) then // Level up!
		PlayerLevel = PlayerLevel + 1
		DarkRP.notifyAll(0,3,self:Name() .. ' reached level '..PlayerLevel..'!');
		hook.Call( "PlayerLevelChanged" )


		local RemainingXP = (TotalXP-self:getMaxXP())
		if(LevelSystemConfiguration.ContinueXP) then
			if(RemainingXP>0) then
				self:setXP(0)
				self:setLevel(PlayerLevel)
				return self:addXP(RemainingXP,true,true)
			end
		end
		
		self:setLevel(PlayerLevel)
		self:setXP(0)
		net.Start( "test" )
		net.Send( Entity( 1 ) )
		
		DarkRP.storeXPData(self,PlayerLevel,0)
	else
		DarkRP.storeXPData(self,PlayerLevel,(TotalXP or 0))
		self:setXP(math.max(0,TotalXP))

	end
	return (amount or 0)

	end

Baso, the issue is that the text does not stop. I want it to scroll across the screen then just go away after it gets to the end but it just keeps reverting back to the start and repeating itself.

You added a hook, but never removed it. It will keep drawing that thing forever. Add an “IF” block that calls hook.Remove( “HUDPaint”, “DrawScrollText” ) when its position is outside the screen.

How would I do that, I know how to make if statements but I’m not sure how’d I make it so it works when the position is outside of the screen.



surface.CreateFont( "ScoreboardText", {
	font = "Colaborate-Regular",
	size = 55,
	weight = 500,
	antialias = true,
	shadow = true,
} )

local multiplier = 120			-- greater multiplier = faster scroll
local width = ScrW() 			-- the width of hte space which the text will scroll across
local xpos = 0				-- the x pos on the screen
local ypos = 500				-- the y pos on the screen, assuming the text scrolls horizontally
local text = "Hello, World!"  	-- the text to draw
local font = "ScoreboardText"	-- the font to draw it in
local textcol = color_white		-- the color to draw the font
net.Receive( "test", function( len, ply )
	xpos = 0
	hook.Add("HUDPaint","DrawScrollText",function()
		xpos = math.fmod(SysTime() * multiplier,width)
		if xpos >= width - 1 then
			hook.Remove("HUDPaint","DrawScrollText")
		end
		draw.DrawText(text,font,xpos,ypos,textcol)
	end)
end)


test it idk