Exit Vehicle

How come this lets me exit my bike :open_mouth:

[lua]

function GM:CanExitVehicle ( ply )
ply:ChatPrint(“You can’t exit this vehicle. Moahahahaha!”)
return false
end

function SpawnBike( ply )
local hoverbike = ents.Create(“prop_vehicle_airboat”)
local tr = ply:GetEyeTrace()
hoverbike:SetModel(“models/hoverbike.mdl”)
hoverbike:SetPos(tr.HitPos)
hoverbike:SetKeyValue(“vehiclescript”,“scripts/vehicles/hoverbike_script.txt”)
hoverbike:Spawn()
hoverbike:Activate()
ply:EnterVehicle( hoverbike )
end
concommand.Add( “SpawnBike”, SpawnBike )

[/lua]

Where is this being called?

If i remember correctly, you can’t access the GM after the gamemode has being initialized. You need to use hook.Add(“CanExitVehicle”, “DontExitVehicle”, “myFunc”)

Oh crap I forgot.
My bad :smiley:

-snip- I’m being stupid.

well this is my code now and it doesn’t work

[lua]

function exit_bike ( ply )
ply:ChatPrint(“You can’t exit this vehicle. Moahahahaha!”)
return false
end

hook.Add(“CanExitVehicle”, “DontExitVehicle”, exit_bike)

[/lua]

You did check for errors right? I tested it and it’s giving a “attempt to call method ‘ChatPrint’ (a nil value)”

Without that line it works fine.

I brought it up to my ded server got that same error removed it and it works.
Must be one of the addons I have installed

The whole issue is because the wiki has given the wrong arguments.

The 1st argument is the vehicle, the 2nd the player

[editline]11:25PM[/editline]

Updated it for you: