Error when using ScreenFade on GMOD

9 Posts

Help me please, im stalled and cant figure it out lol


Lua

[lua]
function SWEP:PrimaryAttack()
if ( !self:CanPrimaryAttack() ) then return end
local teleportPos = self.Owner:GetEyeTrace().HitPos
if(self.Owner:GetEyeTrace().HitWorld)then

	local plyPos = self.Owner:GetPos()
	if(teleportPos:Distance(plyPos)<1200)then
	for i,v in ipairs(player.GetAll())do
	if(v:GetPos():Distance(teleportPos)>100	)then

	else
		return false
	end
end
if CLIENT then
		self.Owner:ScreenFade( SCREENFADE.OUT, color_black, 0.3,0.3 ) 
	timer.Create( "UniqueName", 0.3, 1, function()  
		self.Owner:ScreenFade( SCREENFADE.IN, color_black, 0.3,0.3 )  
end
	self.Owner:SetPos( teleportPos ) end )
	self:EmitSound ("teleport.wav",100,100 )
end


end
end

[/lua]

Console


    [ERROR] addons/slendermanswep/lua/weapons/slenderman/shared.lua:51: attempt to call method 'ScreenFade' (a nil value)
      1. unknown - addons/slendermanswep/lua/weapons/slenderman/shared.lua:51

    mod_studio: MOVETYPE_FOLLOW with no model.
    mod_studio: MOVETYPE_FOLLOW with no model.
    [DamienTehDemon|3|STEAM_0:0:59291866] Lua Error:

    [ERROR] addons/slendermanswep/lua/weapons/slenderman/shared.lua:51: attempt to call method 'ScreenFade' (a nil value)
      1. unknown - addons/slendermanswep/lua/weapons/slenderman/shared.lua:51



ScreenFade is a server method. Replace “if CLIENT then” with “if SERVER then”.

Make sure you use the wiki in future, you could have looked it up there easily:

Can I ask why ScreenFade is a server side method? It’s a bit of a weird place to have something display related.

UTIL_ScreenFade

I’m guessing this is the same function used to fade in between rounds of CSS. At least I remember maps like atix_helicoptor using some fade event between rounds. So it’s probably called by brush entities on the map which are only available to the server. In turn the server sends a net message to the clients telling them to fade. Didn’t look into it so this is just my hypothesis.

It’s a convenience function really, this effect can be very easily replicated by using HUDPaint hook.

Thats why it confused me, thought it was client ahaha.