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

Why isn't this script not deleting the parent, am I ment to add a loop?

Asked by 4 years ago
Edited 4 years ago

This is for when the generator dies the parent is destroyed

if script.Parent.Generator.Health <= 0
then
    script.Parent:Destroy()
end

0
Yes add a while loop JesseSong 3916 — 4y

1 answer

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

This is because it only runs once, when the server first boots up. You should do:

while true do
    if script.Parent.Generator.Health <= 0 then
        script.Parent:Destroy()
    end
    wait()
end

edit: if someone sees this, the comment's reply is actually the more "correct" answer. try

script.Parent.Generator:GetPropertyChangedSignal("Health"):Connect(function()
    if script.Parent.Generator.Health <= 0 then
        script.Parent:Destroy()
    end
end)

this will run more efficiently

0
thx ill try it FluffySheep46209 369 — 4y
0
Or script.Parent.Generator.Health:GetPropertyChangedSignal("Helath"):Connect(function() because then you don't need the loop Spjureeedd 385 — 4y
0
Thx it worked FluffySheep46209 369 — 4y
Ad

Answer this question