Jump to content

[Solved] Unsuccesful character scaling


Recommended Posts

Ladies and Gentleman,

Please welcome today evening's "What have I coded wrong?"  show's brand new guest: Character scaling!

So, I've been tinkering with this coding for a while now, but I can't figure out what do I code wrong:

Spoiler

 

local function greatestevil(inst)
local health = inst.components.health.current

if inst:HasTag("playerghost") then return end
if inst.components.health:IsDead() then return end

    -- stage I
    if health <= 150 then
        inst.Transform:SetScale(1.2, 1.2, 1.2)
    end
    
    -- stage II
    if health >= 151 and health <= 350 then
        inst.Transform:SetScale(2.2, 2.2, 2.2)        
    end
    
    -- stage III
    if health >= 351 and health <= 500 then
        inst.Transform:SetScale(3.2, 3.2, 3.2)        
    end
    
    -- stage IV
    if health >= 501 then
        inst.Transform:SetScale(4, 4, 4)        
    end
end

 

local master_postinit = function(inst)

    inst:ListenForEvent("healthdelta", greatestevil)

    inst.OnNewSpawn = function(inst)
        Health:SetCurrentHealth(150)
    end

 

It crashes the game and it says: attempt to compare nil with number (here:  if health <= 150 then)

Help my poor soul.

Edited by BillTheCipher
Link to comment
Share on other sites

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
 Share

×
×
  • Create New...