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

How can i make my script count NPC's deaths for a health change based on its death value?

Asked by 5 years ago

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!

1local human = game.Workspace.testfighter.Humanoid
2 
3local count = human.Died.Value
4 
5 while human.Died:Wait(count) do
6    count = count + 1
7    print(count)
8    end

1 answer

Log in to vote
1
Answered by
aredanks 117
5 years ago

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.

1local human = game.Workspace.testfighter.Humanoid
2 
3local count = 0 -- starter count
4 
5human.Died:Connect(function() -- event tied to function
6    count = count + 1 -- keeps increasing at each death
7    print(count)
8end)

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.

Ad

Answer this question