Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

can anyone tell me why it doesnt destroy OR subtract one from the mobvalue?

idk what I coulda gotten wrong

local mobnumb = game.ServerScriptService.DeathCheck.MobNumber
wait(5)
if script.Parent.Health == 0 then
    wait(0.1)
    script.Parent.Parent:Destroy()
    mobnumb.Value -= 1
end

2 comments

0

Have you tried printing to see if the code has executed? It could be that Health is not equal to 0 at that time.

0

The problem here is after 5 seconds it checks if the NPCs health is 0 and if it isn't then it will move on and never check again.

2 answers

✓ Accepted answer

I'm guessing your NPCs use humanoids so you can used the .Died event.

A script in the NPC:

local npc = script.Parent 
local humanoid = npc:FindFirstChildOfClass("Humanoid")
local mobNum = game.ServerScriptService.DeathCheck.MobNumber

humanoid.Died:Connect(function()
    mobNum.Value -= 1
    task.wait(0.1)
    npc:Destroy() 
end)

The issue with the value not being subtracted one is that I'm assuming you're attempting to access a local variable within DeathCheck that is only local to that script. So pretty much you're minusing one from nothing. A way I use whenever I want to have a value from a script able to be changed by anyone is by creating a folder within the player

Example:

game.Player.Playeradded:Connect(function()
	local folder = instance.new("Folder", player)
	folder.name = "Whatever"

	local mobnumb = instance.new("NumberValue", whatever)
	mobnumb.Name = "mobnumb"
	mobnumb.Value = 100
end)

whenever you want to minus it

player.Whatever.mobnumb.Value -=1

for the destroying part I'd have to see what you're attempting to destroy

1 comment

0

well im trying to destroy an npc whenever its health is under 0 it gets destroyed and it subtracts 1 from the intvalue "mobnumber" and whenver the mobvalue == 0 then you win the game"

This discussion is preserved as it was. New answers, comments, and votes are closed.