Hey guys, I’ve written a small block of lua code in a very simple gamemode that I’ve made. It is supposed to wait until a user holds down the space button and then it will repeatedly increase a vector every second until the person releases the space key or until it reaches the maximum vector which I have set. It then adds this vector as a velocity to the player.
But it crashes gmod every time I hold the space button.
Can anyone figure out why? Here’s the code:
function GM:Move( ply, mv )
if ( mv:KeyPressed( IN_JUMP ) ) then
local jump = Vector(0, 0, 0)
while( mv:KeyDown( IN_JUMP ) and jump ~= Vector(0, 0, 2500 )) do
timer.Simple( 1, function() jump = jump + Vector(0, 0, 1) end )
local vel = mv:GetVelocity()
vel = vel + jump
mv:SetVelocity( vel )