CreateThread returns a handle to the created thread, which you can use with TerminateThread to terminate the thread.
For example:
function main()
Wait(500)
local thread = CreateThread("F_PrintShit")
while true do
if IsButtonBeingPressed(3,0) then
TerminateThread(thread)
end
Wait(0)
end
end
function F_PrintShit()
while true do
TextPrintString("shit",0,1)
Wait(0)
end
end
Pressing the zoom-out button there will stop shit from being printed.