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

Function only gets called once??

Asked by 6 years ago
Edited 6 years ago

The monsterExp function only gets called once. I assume it is because the monster variable gets emptied when to gameObject gets destroyed. Is there any way to work around it. Also, another question, can you make labels update "live" and not after character reset?

monster1 = game.Lighting.Zombies
monster1.Parent = game.Workspace

exp = 0
level = 1
expreq = level*25 + 100
gold = 100
game.StarterGui.StatsGui.Level.Text ="Level: "..level
game.StarterGui.StatsGui.Exp.Text = "Exp: "..exp.."/"..expreq
game.StarterGui.StatsGui.Gold.Text = "Gold: "..gold


monster = workspace.Zombies.Zombie.Zombie
function monsterExp()
    print('hej')
    if monster.Health <= 0 then
        exp = exp + 25
        print(exp)
        game.StarterGui.StatsGui.Exp.Text = "Exp: "..exp.."/"..expreq
        print(game.StarterGui.StatsGui.Exp.Text)
    end
end

monster.HealthChanged:connect(monsterExp)

0
In 'if monster.Health <= 0', your trying to say if the monster's health is less than 0 (like -1) then it will add exp? Or your trying to say, 'if monster.Health == 0', which means that if the monster is dead. awesomeipod 607 — 6y
0
Instead of monster.Health <= 0 Change it to monster.Health 1 so it will give you the Exp/XP and you will also kill it! RB Username: SniperXShots SniperXShots -5 — 6y
0
Doesn't really matter if it is 1 or 0, the problem is that the function gets called after the first time when the monster dies, but not the second time allecoo1 0 — 6y

Answer this question