Flickering opaquity on player model problem

Hey, i’m having a problem with this set of code:
if self.NextHit then
owner:SetColor(20, 20, 20, 200)
owner:SetColor(20, 20, 20, math.min(owner:GetVelocity():Length(), 200))
This set of code is used in the init think fucntion for a weapon. it’s supposed to make the player invisible while standing still, and visible when moving. trouble is, is that when people are/arent moving, the color flickers from visible to invisible. almost like a short-circuited lamp. it’s not steady, it’s random. What am i doing wrong here? Should i be running this code in the gamemode and not the weapon?

What does the “self.NextHit” variable provide?
“init think function”, Do you mean the think function?
SetColor accepts a Color table, not 4 arguments. Color(20,20,20,200)

Self.NextHit determines when the next hit is, since the SWEP is a melee weapon. it’s function is to make the player visible while self.NextHit is valid.

Yes, i mean the think function.

What do you mean by it accepts a color table and not 4 arguments? those 4 arguments have proven to work on many other things i’ve made

Try [lua]if owner:GetVelocity():Length()>0 then
owner:SetColor(20, 20, 20, 200)
owner:SetColor(20, 20, 20, 0)


You can’t multiply a bool by an integer without doing some debug.setmetatable magic.

Ah yeah, you’re right, just a personal preference. I don’t think it works on draw stuff however.