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)
Replace your current function and connection with this:
monster = workspace.Zombies.Zombie.Zombie function monsterExp() print('hej') --if monster.Health >= 0 then -- don't need this anymore exp = exp + 25 print(exp) game.StarterGui.StatsGui.Exp.Text = "Exp: "..exp.."/"..expreq print(game.StarterGui.StatsGui.Exp.Text) --end end monster.Died:connect(monsterExp)
monster1 = game.Lighting.Zombies -- change to ServerStorage 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 -- what the f***? function monsterExp() print('hej') if monster:FindFirstChild("Humanoid") == nil then Instance.new("Humanoid",monster) end exp = exp + 25 print(exp) game.StarterGui.StatsGui.Exp.Text = "Exp: "..exp.."/"..expreq print(game.StarterGui.StatsGui.Exp.Text) end if monster.Humanoid.Died:Wait() then monster.Humanoid.Died:Connect(monsterExp) end