Hello, I am trying to make a script that will change the health of an NPC based on the number times it respawns. Ive got a respawn script to work, however, i am trying to get a script to count its deaths. (Note: I havent tried to change the health yet until i can get a number for the deaths.) Below is my script so far...If i made a simple mistake or something stupid, please dont be afraid to call me stupid because i want to learn from my mistakes. Thank you so much!
local human = game.Workspace.testfighter.Humanoid local count = human.Died.Value while human.Died:Wait(count) do count = count + 1 print(count) end
That is not proper use of a while loop. What I believe you're trying to do is quite the same as an event-connected function so attach it to a function instead of :Wait() since you're attempting to get every single time the NPC dies. Also you can use a number instead of creating a unnecessary instance to record your numbers as variables can hold numbers.
local human = game.Workspace.testfighter.Humanoid local count = 0 -- starter count human.Died:Connect(function() -- event tied to function count = count + 1 -- keeps increasing at each death print(count) end)
This will track each time the NPC dies and runs the code within the function each of those times. It will also count numbers more efficiently then using a NumberValue or IntValue since those are created objects.