Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

If statement not running when I use a random number generator?[SOVLED]

Asked by 5 years ago
Edited 5 years ago

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

0
An if statement won't "fire". Execute is what you're looking for. "Fire" refers to an event notifying its listeners. User#19524 175 — 5y
0
You know what I mean XD GottaHaveAFunTime 218 — 5y
0
Try doing math.random(15,20) instead. waifuSZN 123 — 5y
0
But... math.random isnt realllly random. Thats why I am trying to use random.new() GottaHaveAFunTime 218 — 5y
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. User#19524 175 — 5y

Answer this question