Okay so on Line 2 if I remove the randomness from that and make it the same number everytime the if statement below works fine. (If statment is on line 7)

But when I add a random number generator like i have above. The if statement never fires.

            if HitPart.Parent.Humanoid.Health > 0 then
                HitPart.Parent.Humanoid:TakeDamage(Random.new():NextNumber(15, 20))
                
                HitPart.Parent.HealthGui.MainFrame.Bar:TweenSize(UDim2.new(HitPart.Parent.Humanoid.Health/HitPart.Parent.Humanoid.MaxHealth, 0, 1, 0), "Out", "Quad", .25, true)
                
                    
                if HitPart.Parent.Humanoid.Health == 0 then
                    if HitPart.Parent:FindFirstChild("Dead") == nil then
                        local Debounce = Instance.new("IntValue")
                        Debounce.Name = "Dead"
                        Debounce.Parent = HitPart.Parent
                    
                        ReplicatedStorage.RoundStats.CurrentEnemyCount.Value = ReplicatedStorage.RoundStats.CurrentEnemyCount.Value - 1
                        ReplicatedStorage.RoundStats.EnemiesLeft.Value = ReplicatedStorage.RoundStats.EnemiesLeft.Value - 1

                        DebrisService:AddItem(HitPart.Parent, GameSettings.EnemySettings.EnemyDespawnTime)
                    end
                end
            end

Can anyone help me to understand this? The humanoid dies so its health is at 0 so It confuses me as to why it isnt firing.

I HAVE SINCE SOLVED THIS I just changed .Health == 0 to .Health <= 0

5 comments

0

An if statement won't "fire". Execute is what you're looking for. "Fire" refers to an event notifying its listeners.

0

You know what I mean XD

0

Try doing math.random(15,20) instead.

0

But... math.random isnt realllly random. Thats why I am trying to use random.new()

0

What? math.random now follows the same algorithm as Random.new now, what's the point of saying that, but Random.new has its other benefits nonetheless.