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

How do I put a script inside a player's body parts when it dies?

Asked by 9 years ago

Before anything else, I just like to mention that I'm an absolute noob in scripting. I know there is a lot to improve on the script I will show you. The redundancies might make you cringe.

I'm trying to make a death effect similar to getting shot by the Hyperlaser Gun gear. So, whenever a player dies, the body parts become anchored and transparent; selection boxes and lights will appear and fade out; and eventually the parts are destroyed. I made a function that does exactly that.

THE PROBLEM: * I have no clue how to integrate the function into a player's body parts whenever someone dies.*

I heard it has to do something with the "Died()" event. How do I do it?

Here's the "HyperDeath" function

local function HyperDeath(instance) 
    local function SelectionBoxify(instance)
        local selectionBox = Instance.new('SelectionBox')
        selectionBox.Adornee = instance
        selectionBox.Color = BrickColor.new('New Yeller')
        selectionBox.Parent = instance
        selectionBox.Transparency = 0.3
        return selectionBox
    end

    local function Light(instance)
        local light = Instance.new('PointLight')
        light.Parent = instance
        light.Color = Color3.new(255,255,0)
        light.Range = 7
        return light
    end

    local function Freeze(instance)
        local part = instance
        part.Anchored = true
    end

    local function Hide(instance)
        local part = instance
        part.Transparency = 1
    end

    local function FadeSelection(instance)
        local part = instance.SelectionBox
        local increment = 0.05
        while part.Transparency < 1 do
            part.Transparency = part.Transparency + increment
            wait()
        end
    end

    local function Vanish(instance)
        local part = instance
        part:Destroy()
        part.Parent = instance
    end


    SelectionBoxify(instance)
    Light(instance)
    Freeze(instance)
    Hide(instance)
    wait(0.5)
    FadeSelection(instance)
    wait(1)
    Vanish(instance)
end

Am I on the right track? Or am I totally way off? Thank you in advance for your feedback. :D

1 answer

Log in to vote
0
Answered by 9 years ago

In your gun, you should check if Humanoid.Health-Damage is <=0 and if so, run

local p = Humanoid.Parent:children()
for i=1,#p do
    if p:IsA("Part") then
        coroutine.wrap(HyperDeath)(p)
    end
end

The confusing part of that snippet is the part about coroutines - because your function has wait(0.5) and other waits in it, each function call would wait before returning so it would only do the effect at one part of the character at a time. Also make sure that "Humanoid" in the above snippet is the character's humanoid, the variable might be named "human" in your gun instead.

0
You COULD use a Died event for this instead of integrating it into your gun, but then every single time the player dies instead of only when he died from being shot it would trigger. RenderSettings 35 — 9y
0
I'm actually going for two options: using it every time the player dies, or integrating it with the LinkedSword (not a gun). How do I use the Died event? paladinslayer 0 — 9y
Ad

Answer this question