Laser shooting from car

I am making a laser shoot from the front of the car and the explosion works fine and hits where I want it to but the tool tracer is not showing, I am getting no errors and not sure why it wont work. I did make it as a sent and it worked but it was cleaner having it in the init.lua. Any help will be greatly appreciated. Thanks

This is what i have in the init.lua
local function ShootLaser(ply)

local jeep = ply:GetVehicle()

if not ValidEntity(jeep) then return end
local tracedata = {}
tracedata.start = jeep:GetPos()
tracedata.endpos = (jeep:GetPos() + jeep:GetForward() * 1000000)
tracedata.filter = jeep
local trace = util.TraceLine(tracedata)
if( trace.Hit ) then
    HitPos = trace.HitPos
    HitPos = false

local effectdata = EffectData()
effectdata:SetAttachment( 1 )
util.Effect( "ToolTracer", effectdata )

local explosion = ents.Create( "env_explosion" ) // Creating our explosion
explosion:SetKeyValue( "spawnflags", 144 ) //Setting the key values of the explosion
explosion:SetKeyValue( "iMagnitude", 15 ) // Setting the damage done by the explosion
explosion:SetKeyValue( "iRadiusOverride", 128 ) // Setting the radius of the explosion
explosion:SetPos(HitPos) // Placing the explosion where we are
explosion:Spawn() // Spawning it


function GM:KeyPress(ply,key) – You can easilly do the rest of your key detection here
if key == IN_ATTACK2 then
SpawnBomb(ply) – If right click was pressed then we can call our SpawnBomb function for that player
if key == IN_ATTACK then

[noparse][lua]code here[/lua][/noparse]

You should put your code in Lua tags, it is easier to read.

I did but when i edited it, it took then out so i edited again to put them in :slight_smile:

Some effects require additional parameters in order to actually work. Here is how ToolTracer is used in the STOOL :

	local effectdata = EffectData()
		effectdata:SetOrigin( hitpos )
		effectdata:SetStart( self.Owner:GetShootPos() )
		effectdata:SetAttachment( 1 )
		effectdata:SetEntity( self.Weapon )
	util.Effect( "ToolTracer", effectdata )

That means you should probably be setting an Entity, and then you might have to change the attachment because you don’t know which of the car’s attachment has the number 1.

Of course I could be entirely wrong, I haven’t tested any of this.

Ok well after a long break I came back to the gamemode and tested it single plyer how the script was above and it worked perfectly so why wouldent it work multiplayer. (I aslo added the SetEntity that you suggested crazy not sure if it did anytihng but ill leave it there for the moment)