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

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

Asked by 2 years ago
Edited 2 years ago

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
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. PhantomVisual 992 — 2y
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. SimpleFlame 255 — 2y

2 answers

Log in to vote
2
Answered by 2 years ago
Edited 2 years ago

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)
Ad
Log in to vote
0
Answered by
Lagfss 36
2 years ago

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

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" StevenElijah7019 57 — 2y

Answer this question