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 10 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

01local function HyperDeath(instance)
02    local function SelectionBoxify(instance)
03        local selectionBox = Instance.new('SelectionBox')
04        selectionBox.Adornee = instance
05        selectionBox.Color = BrickColor.new('New Yeller')
06        selectionBox.Parent = instance
07        selectionBox.Transparency = 0.3
08        return selectionBox
09    end
10 
11    local function Light(instance)
12        local light = Instance.new('PointLight')
13        light.Parent = instance
14        light.Color = Color3.new(255,255,0)
15        light.Range = 7
View all 53 lines...

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 10 years ago

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

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

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 — 10y
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 — 10y
Ad

Answer this question