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

why doesn't my shield disappear after dying the 2nd time?

Asked by 3 years ago
-- Variables --
local Char = script.Parent["Remilia Scarlet"] -- npc name
local Shield = script.Parent.Shield
local Hum = script.Parent["Remilia Scarlet"].Minor
local Health = script.Parent["Remilia Scarlet"].Minor.Health
local FractionOfMaxHealth = script.Parent["Remilia Scarlet"].Minor.MaxHealth/1
local Storage = game:GetService("ServerStorage")
local ToClone = Storage:WaitForChild("Shield")
local HumPart = Char.HumanoidRootPart
local IMBACKID = "rbxassetid://7128573459"
local BRUHWHYDIDIDIE = "rbxassetid://7128572620"
-- Functions --
Hum.HealthChanged:Connect(function(Health)
    if Health == FractionOfMaxHealth then
        wait(3)
        local GuessWhosBack = Instance.new("Sound")
        GuessWhosBack.Parent = HumPart
        GuessWhosBack.SoundId = IMBACKID
        GuessWhosBack.PlayOnRemove = true
        GuessWhosBack.Volume = 1
        GuessWhosBack.RollOffMaxDistance = 696
        GuessWhosBack.RollOffMode = ("Linear")
        GuessWhosBack:Destroy()
        local ForceField = Instance.new("ForceField")
        ForceField.Parent = Char
        ForceField.Visible = false
        local Cloned = ToClone:Clone()
        local ClonedRoot = Cloned.HumanoidRootPart
        ClonedRoot.Position = Char.WorldPivot.Position
        Cloned.Parent = script.Parent
        local weld = Instance.new("Motor6D")
        weld.Part0 = HumPart
        weld.Part1 = ClonedRoot

    end
end)

Shield.Minor.Died:Connect(function()
    wait(0.01)
    Shield.HumanoidRootPart.Transparency = 0.5
    wait(0.01)
    Shield.HumanoidRootPart.Transparency = 0.4
    wait(0.01)
    Shield.HumanoidRootPart.Transparency = 0.3
    wait(0.01)
    Shield.HumanoidRootPart.Transparency = 0.2
    wait(0.01)
    Shield.HumanoidRootPart.Transparency = 0.2
    wait(0.01)
    Shield.HumanoidRootPart.Transparency = 0.1
    wait(0.01)
    Shield.HumanoidRootPart.Transparency = 0
    wait(0.01)
    Char.ForceField:Destroy()
    Shield.HumanoidRootPart:Destroy()
    wait(0.01)
    Shield:Destroy()
    local ShieldBreakSound = Instance.new("Sound")
    ShieldBreakSound.SoundId = BRUHWHYDIDIDIE
    ShieldBreakSound.PlayOnRemove = true
    ShieldBreakSound.RollOffMaxDistance = 696
    ShieldBreakSound.RollOffMode = ("Linear")
    ShieldBreakSound.Parent = Char.HumanoidRootPart
    ShieldBreakSound.Volume = 1
    ShieldBreakSound:Destroy()
end)

what this script is supposed to do is have the shield reappear after my npcs health is full the sheild reappears and delete when i kill it but when i kill it the shield does not disappear after reappearing which is weird does anyone have an explanation?

Answer this question