ShouldCollide hook crashes the server

It works perfectly fine for me, but when another player tries to go through it, the server crashes, but it doesn’t always do that. It’s weird. Need some help.



hook.Add("ShouldCollide", "Collision", function(ent1, ent2)
    if ent1:GetClass() == "morphine" and ent2:IsPlayer() then
        local teamname = ent2:getDarkRPVar("job")

        if teamname == "Civil Protection" or teamname == "Mayor" or teamname == "SWAT" then
            ent1:SetCollisionGroup(11)
        else
            ent1:SetCollisionGroup(0)
        end

        return true
    end
end)

Why are you setting the collision group? Just return false if the player’s in the job.


hook.Add("ShouldCollide", "Collision", function(ent1, ent2)
	if ent1:GetClass() == "morphine" and ent2:IsPlayer() then
		local teamname = ent2:getDarkRPVar("job")
		return not (teamname == "Civil Protection" or teamname == "Mayor" or teamname == "SWAT")
	end
end)


Yes that works like a charm but it also disables all collisions with bullets. Since I made the morphine entity destructible. Any way i could exclude the bullets from the return false?

[editline]3rd September 2017[/editline]

Actually nevermind, that was doing it because I was testing it while i was a cop lmfao. Thanks a lot man!