local gateCommandWaitInMs = 3000 -- 3000 milliseconds. You can increase or decrease this value to meet your requirements
local objectMovingTick = getTickCount() + gateCommandWaitInMs -- we are adding this to tick, so we don't have to wait for 3 seconds in first use
gateLSPD = false
x, y, z = getElementPosition ( source )
if getDistanceBetweenPoints3D ( x, y, z, 1544.24707, -1631.90906, 13.38281 ) <= 2 then
if (objectMovingTick - getTickCount()) < gateCommandWaitInMs then -- check if 3000 milliseconds have passed
return
end
if gateLSPD == false then
local rotX, rotY, rotZ = getElementRotation(shlagLSPD)
moveObject ( shlagLSPD, 2000, 1544.6999511719, -1630.9000244141, 13.10000038147, 0, -80, 0 )
gateLSPD = true
else
local rotX, rotY, rotZ = getElementRotation(shlagLSPD)
moveObject ( shlagLSPD, 2000, 1544.6999511719, -1630.9000244141, 13.10000038147, 0, 80, 0 )
gateLSPD = false
end
objectMovingTick = getTickCount()
end
You can use getTickCount to fix the problem.