Help me disabling material.

Hello there internet! I just added a new thing to my server. A thing so you cant material vehicles. But when i start the server i get lua errors. Wich says. GM is nil value. please help.
This is what the code is like:

function GM:CanTool( ply, tr, tool )
if ( tool == “material” and IsValid( tr.Entity ) and tr.Entity:GetClass() == “prop_vehicle_jeep” ) then
return false
end
end

OMG, stop recreating your threads. Be patient or get help yourself. You should start by googling “gmod hook.Add”

First off, you should use [noparse]


 

[/noparse] tags for writing code on the forum

Second, you’re doing it wrong. You need to use a hook rather than actually using GM:function() - those are defined by the gamemode itself and can’t be accessed by other addons.

This is what you want to do:


function CanMaterialVehicles( ply, tr, tool )
	if ( tool == "material" and IsValid( tr.Entity ) and tr.Entity:GetClass() == "prop_vehicle_jeep" ) then
		ply:ChatPrint("You're not allowed to use "..tool.." on "..tr.Entity:GetClass()..".")
		return false
	end
end
hook.Add("CanTool","CanMaterialVehicles",CanMaterialVehicles)


This.
If you look at all three of the threads, they’re practically the same question all posted within the same day.

http://puu.sh/7bIW4/8d6c4c7135.png

Shouldn’t really encourage this.

Thank you all for your answears! Really helped me out! Thanks! :smiley: