When I get ONE hit from an enemy bullet
I can see the health bar decrease,
But when I get a second hit by a bullet
The game crashes and I get this error.

Invailed access to property or key value on a base object of type null instance"

How to return a value going from 30 to 0?

How can I make the game not crash with the second bullet hit by an enemy?

What is the code?
where to put it


    RaidenJTr7 whatever the problem is youre progressbat is null.. meaning you deleted it somehow.. look where you delete it

    hi,

    for the error "Invalid access to property or key value on a base object of type null instance".
    How do you instantiate the bullet? And to see if it is the bullet that is the problem, comment out queue_free() in the body entered function and check if the error is still there.

    How to return a value going from 30 to 0?
    You can use the clamp(value, min, max) method to force the value to be between 30 and 0. like clamp(value, 0, 30)
    I would suggest to create an export variable for the min and max so its easier to change the values and reuse the bullet script for other bullets or so.

    How can I make the game not crash with the second bullet hit by an enemy?
    It is difficult to say since we don't have all the code to debug and check for errors. My suggestion is to comment out the queue_free() function in the bullet and see if the error is still there.
    How and where are you creating the bullet?
    In the Debugger tab under Stack Trace it will show the functions that were called before it crashed. Can you send a screenshot of the code in those functions?

    What is the code? Where to put it?
    These questions are way too vague and will most likely be ignored. Not having all the code of your project makes it very difficult to code a solution.

      PotatoArmor

      I removed the queue_free()

      Stil the game crash after the second hit from enemy bullet

      -

        • Edited

        RaidenJTr7 print is your essential tool when debugging. Print progress_bar in _ready() to see if it's getting initialized properly and print self.path in that signal handler that causes the error to see if the script is attached to the node you expect it to be.

        @RaidenJTr7 is perhaps the parent node of the progress bar being deleted? Deleting a parent node will also delete all of its children nodes.

        RaidenJTr7 why are you takin screenshots with camera? Youre on windows, get sharex.. jees.. or maybe just use sniping tool that is built in.

        But like i said earlier, the progressbar node is deleted somehow.. it is nul..

        Maybe just do a check if not null then minus the value?

        @"DaveTheCoder"#p150786 that value var is part of the progressbar private var.

        I think there is two body problem here.

        He ahs multiple collision shapes, and assicitated functions when somehting enters.

        In the first a bodu enters and if its a player then body gets hit and then it queeue free.
        And then the code try to execute the next collisionshape function on hurt body enters and tries to do the progressbar value but it cant becasue it got deleted..

        if OP already has function body.hit() then why not add the progressbar update to that function.

        OP needs to rethink how to hook up signals and stuff otherwise its a mess..

          @RaidenJTr7 hurt box body entered and enemy bullet body entered does the same thing.

          How have you structured your scenes?
          Where have you created your progress bar?
          As @kuligs2 mentioned you have multiple on body entered functions.
          What are the 3 on body entered functions supposed to do?
          Can you not use 1 collision shape instead of the 3?
          Is there any other code that changes the progress bar?
          Because as you have tested that after removing queue_free() from the bullet script the error is still there so the progress bar or the parent node of the progress bar must be deleted from somewhere else causing the progress bar to be null when trying to decrease its value in both hurt box body entered and enemy bullet body entered.