Hi I am pretty new to script from scratch and I need help on how to create a script where if the dummy is dead, then the part in the same group as the rig will disappear.
– Function to check health
local function checkHealth(character)
local humanoid = character:FindFirstChildOfClass(“Humanoid”)
if humanoid then
if humanoid <= 1 then
– make the Part in the group visable to 1
part.CanCollide = false
part.Transparency = 1
end
end
end
(I put the script in the dummy or rig and out side is that group that is just a part and the rig.)
there is something known as Humanoid.Died and it exists just for this reason
local part = path.to.part -- change this to wherever the part is
local character = path.to.dummy -- change this to wherever the dummy is
local humanoid = character:FindFirstChildOfClass(“Humanoid”)
-- function
local function Died()
-- make the Part in the group visable to 1
part.CanCollide = false
part.Transparency = 1
-- you can also use part:Destroy() if you want it completely gone
end
humanoid.Died:Once(Died) -- this will do the function when humanoid.Health reaches 0
part = script.Parent.Parent.Part
local Character = path.to.Dummy -- If the script is parented to the Rig then you can do script.Parent
local Humanoid = Character:FindFirstChild("Humanoid")
if Humanoid.Died:Connect(function()
part.CanColide = false
part.Transparency = 1
end)
local Part = game.Workspace:FindFirstChild("PartName")
local Humanoid = script.Parent:FindFirstChild("Humanoid")
local function onHumanoidDeath()
Part.CanCollide = true --// Make that you cannot walk through the part
Part.Transparency = 1 --// Makes the part transparent.
end
Humanoid.Died:Once(onHumanoidDeath)
I think you forgot to use function when humanoid’s health is changed
local function checkHealth(character)
local humanoid = character:FindFirstChildOfClass(“Humanoid”)
if humanoid then
if humanoid.Health <= 0 then
part.CanCollide = false
part.Transparency = 1
end
end
end
Script.Parent.Humanoid.HealthChanged:Connect(checkHealth)
(Srry if i understanded something wrong cause I’m bad at english lol, but I hope it helps you, tell me if theres any issues)
local function checkHealth()
local Humanoid = script.Parent:FindFirstChild("Humanoid")
if Humanoid.Health == 0 then
Part.CanColide = false
Part.Transparency = 1
end
script.Parent.Died:Once(checkHealth)
As the >= means (equal or less than), we don’t really need it as == means equal to so as the Dummy (rig)'s health equals to 0 then we don’t need the Rig’s Health >= less than or equal to 0