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

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

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

✓ Accepted answer

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!

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)

3 comments

0

Thank you!!

0

I didn't know you could this with a dummy, I thought it had to be a real player

0

Died is an event of Humanoid not Player. So it should be good as long as the dummy has a humanoid.

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