Jump to content

need help with player level


itHyperoX

Recommended Posts

Hi, im trying to create my own level system, but i got some problem. I tried a few way, but always gettint debug errors and i dont know how to fix that.

 

Debug error:   sourceS: Line 8: attempt to compare boolean with number

 

Here is the server side:

exports.scoreboard:scoreboardAddColumn("Level") 
function setPlayerLEVEL(player)
for _,player in ipairs(getElementsByType("player")) do
local currentPlayerLevel = getElementData(player,"pLevel" or 0)

if currentPlayerLevel < 5 then  --- Line 8
setElementData(player,"Level",2)
end

if currentPlayerLevel >= 10 and currentPlayerLevel < 15 then
setElementData(player,"Level",3)
end

if currentPlayerLevel >= 20 and currentPlayerLevel < 30 then
setElementData(player,"Level",4)
end

if currentPlayerLevel >= 30 and currentPlayerLevel < 40 then
setElementData(player,"Level",5)
end


end
end
setTimer(setPlayerLEVEL,500,0)

 

 

Here is the client side:

 

setTimer(function()
    if getElementData(localPlayer,"pLevel" or 0) then
        setElementData(localPlayer,"pLevel",getElementData(localPlayer,"pLevel") + 1)
    end
end, 10*600, 0)

 

Thanks any help.

Or can i make it easier?

Edited by TheMOG
Link to comment

LOL, now that broke what worked.

 

client: 

setTimer(function()
    if getElementData(localPlayer,"pLevel" or 0) then
        setElementData(localPlayer,"pLevel",getElementData(localPlayer,"pLevel") + 1)
        outputChatBox(getElementData(localPlayer,"pLevel"))
    end
end, 100, 0)

I dont get anything from this. Whats happened with this? No debug error

Edited by TheMOG
Link to comment

Change line nr. 2 to

if (getElementData(localPlayer,"pLevel") or 0) then

Btw, I dont understand that line at all. You could just do

setTimer(function()
	setElementData(localPlayer, "pLevel", (getElementData(localPlayer, "pLevel") or 0) + 1)
	outputChatBox(getElementData(localPlayer, "pLevel"))
end, 100, 0)

 

Link to comment

Line 9 attempt to perform arthmetic on boolean value

 

 

setTimer(function()
    if (getElementData(localPlayer,"pLevel") or 0) then
        setElementData(localPlayer,"pLevel",getElementData(localPlayer,"pLevel") + 1)  --- Line 9
        outputChatBox(getElementData(localPlayer,"pLevel"))
    end
end, 100, 0)

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...