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

When NPC is killed, set transparency. Script not working. Help?

Asked by 2 years ago

When I kill the NPC, nothing happens. Thoughts? Very new to scripting



while true do if workspace.Dummy.Humanoid.Health <1 then workspace.Cam.Union.Transparency = 1 end end

2 answers

Log in to vote
0
Answered by
CodeWon 181
2 years ago

One thing that might be the problem is that the script is checking to fast. The script can get tired if it is checking the health way to fast. A cleaner meathod is a built-in event called changed, if the health is changed, then the event will fire. Inside the changed event you can check the health.

local health = workspace.Dummy.Humanoid.Health
health.Changed:Connect(function()
    -- Everything below will run when the health changes
    if health == 0 then
        workspace.Cam.Union.Transparency = 1
    end
end)

I hope this works!

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

You can use the Died event of Humanoid which only fires when the humanoid dies. Instead of constantly checking for it's health which is extremely inefficient.

workspace.Dummy.Humanoid.Died:Connect(function()
    workspace.Cam.Union.Transparency = 1
end)
0
Thank you!! epicdogebox 9 — 2y
0
I didn't know you could this with a dummy, I thought it had to be a real player CodeWon 181 — 2y
0
`Died` is an event of Humanoid not Player. So it should be good as long as the dummy has a humanoid. Dehydrocapsaicin 483 — 2y

Answer this question