So,
This line is useless right here,
DProgress:GetFraction()
And var is undefined when you’re doing calculations. Checkout the post by gonzalolog on defining it. I’m assuming the
end)
at the end is for a parent function for all the code.
As per your problem with the error. When the menu gets removed, you also need to remove the hook. So modify your onThink function to look like this
local function onThink()
if (not IsValid(DumpMenu)) then
hook.Remove("Think", "DumpThink")
return
end
print( "test" )
DProgress:SetFraction( 10 - ( CurTime() - var ))
end
However, you shouldn’t really use a separate hook for this. Use a panel think hook which will automatically get removed, like such:
function DProgress:Think()
self:SetFraction(10 - (var - CurTime()))
end
That way you won’t need to check to make sure the panel is valid, and you will have a lot less clutter. Now, going back to Robotboy, you should be doing what he suggested. Here’s a rough idea of what you need to do. Define a variable that is equal to CurTime() before the Think function. In the SetFraction() function, do (timerlength - (CurTime() - variableYouDefined)) / timerlength, to get the fraction you need.