Skip to content

Commit 66f03d5

Browse files
authored
Fix NULL error (#3391)
Fixes: ```lua [Wiremod Canary] lua/wire/stools/holoemitter.lua:39: attempt to call method 'UnLink' (a nil value) 1. RightClick - lua/wire/stools/holoemitter.lua:39 2. unknown - gamemodes/sandbox/entities/weapons/gmod_tool/shared.lua:265 ```
1 parent 234ce88 commit 66f03d5

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

lua/wire/stools/holoemitter.lua

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,18 @@ function TOOL:RightClick( trace )
3434
return false
3535
end
3636
else
37-
if (self.Target == ent or ent:IsWorld()) then
38-
self:GetOwner():ChatPrint("Holoemitter unlinked.")
39-
self.Target:UnLink()
40-
self:SetStage(0)
41-
return true
42-
end
43-
self.Target:Link( ent )
4437
self:SetStage(0)
45-
self:GetOwner():ChatPrint( "Holoemitter linked to entity (".. tostring(ent)..")" )
38+
39+
if IsValid(self.Target) then
40+
if self.Target == ent or ent:IsWorld() then
41+
self:GetOwner():ChatPrint("Holoemitter unlinked.")
42+
self.Target:UnLink()
43+
return true
44+
end
45+
46+
self.Target:Link(ent)
47+
self:GetOwner():ChatPrint( "Holoemitter linked to entity (".. tostring(ent)..")" )
48+
end
4649
end
4750

4851
return true

0 commit comments

Comments
 (0)