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

2 comments
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.
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?