I'm trying to make this script so that when an NPC's health goes below 50 it'll put a shield up, but nothing happens. Filtering Enabled is on.
name="Humanoid" while true do wait(1) if script.Parent.Humanoid.Health<50 then script.Parent.Torso.Proj.Beam.Enabled = true script.Parent.Torso.Shield.Script.Disabled = false script.Parent.Torso.Shield.Transparency = .5 script.Parent.Torso.Shield.CanCollide = true else script.Parent.Torso.Proj.Beam.Enabled = false script.Parent.Torso.Shield.Script.Disabled = true script.Parent.Torso.Shield.Transparency = 1 script.Parent.Torso.Shield.CanCollide = false end end
Thanks if you can help me!
while
loop to do the job a Changed
event should do. Also, place this script in StarterPlayerScripts
, as the script won't run again if the character respawns and the script was placed in StarterCharacterScripts
.local plr = script.Parent.Parent local char = plr.Character or plr.CharacterAdded:Wait() local hrp = char.HumanoidRootPart char.Humanoid.HealthChanged:Connect(function(new) if new <= 50 then hrp.Proj.Beam.Enabled = true hrp.Shield.Script.Disabled = false hrp.Shield.Transparency = .5 hrp.Shield.CanCollide = true else hrp.Proj.Beam.Enabled = false hrp.Shield.Script.Disabled = true hrp.Shield.Transparency = 1 hrp.Shield.CanCollide = false end end)