getPlayerLevel is a server side function, you should use getElementData instead.
maxstamina = 10
addEventHandler ( "onClientPlayerSpawn", getLocalPlayer(),
function ( )
local level = tonumber ( getElementData ( localPlayer, "level" ) or 0 )
maxstamina = ( level * 10 )
setTimer ( checkKey, 700, 0 )
setTimer ( updateStamina, 1000, 0 )
end
)
stamina = maxstamina
function checkKey ( )
if ( getControlState ( "sprint" ) ) and ( stamina ~= 0 ) then
stamina = ( stamina - 1 )
end
if ( stamina == 0 ) then
setControlState( "sprint", false )
end
end
function updateStamina ( )
if ( stamina ~= maxstamina and getControlState ( "sprint" ) == false ) then
stamina = ( stamina + 1 )
end
end
Instead of all the 'if' checks for level, I'd this:
maxstamina = ( level * 10 )
Will do the same, but simplified.