Hello, I want to make death effect for my game.
If health is 0, player’s character turns into this model - screenshot 1
All Motor6Ds connections between arms, legs, head should break - screenshot 2
When connections are broken, all bodyparts fly in the different directions and fall on the ground - screenshot 3
Example:
I have no idea how to make this, please help me with this
I’m nor a animator nor a scripter, but what I can give you is a tutorial I found on Youtube. Maybe try to recreate what he did for your own. Hope you found this helpful. Maybe try to look at other help and feedback post or Roblox Developer site.
I want to make it without using an animation, maybe i should use explosion to make bodyparts fly?
An explosion for itself flies bodyparts
You could use Forces and stuff to give it more ‘power’ and that.,
Humanoids parts automatically get detached when he dies, so yes, you can try an explosion
Humanoid.HealthChanged:Connect(function()
if Humanoid.Health <= 0 then
--instantiate your explosion at the position of humanoid root part
end
end)
Instead of HealthChanged, you could simply use Humanoid.Died to shorten
But that’s good aswell
Ah yes, i forgot about that event, thank you
I welded these parts (red circle), are they going to be detached if player dies?
Hey, I decided to make this just as a challenge for myself:
To do this, insert a LocalScript into StarterPlayerScripts folder:
Paste this code into the LocalScript:
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DeathRemote = ReplicatedStorage:WaitForChild("DeathRemote")
Players.LocalPlayer.CharacterAdded:Connect(function(char)
local Humanoid: Humanoid = char:WaitForChild("Humanoid")
Humanoid.Died:Connect(function()
DeathRemote:FireServer()
end)
end)
Insert a Script into ServerScriptService:
Paste this code into the Script:
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
Players.RespawnTime = 4.3 --Change the respawn time so it'll fit the lengh of death effect. You can change the value, but you'll also need to change wait and tween times
local DeathRemote = ReplicatedStorage:WaitForChild("DeathRemote")
--Putting built-in functions into variables with short names saves space if called many times
local r = math.random
local rad = math.rad
local yOffset = 5 --How high will the parts fly
local Parts = {"Head", "Left Arm", "Left Leg", "Right Arm", "Right Leg", "Torso"}
DeathRemote.OnServerEvent:Connect(function(player) --Connect the event
local Character: Model = player.Character
if not Character then return end --Exit function and do nothing if there is no character
local function GetCFrame(part: BasePart): CFrame? --Put the function here so it'll generate new random values every time the event is fired
local RightVector = part.CFrame.RightVector
local PartToCFrame = {
["Head"] = part.CFrame + Vector3.new(0, 1+yOffset+r(5)/10, 0),
["Left Arm"] = (part.CFrame + (-RightVector+Vector3.new(0, 0+yOffset+r(5)/10, 0)))*CFrame.Angles(170, 0, rad(-r(10, 50))),
["Left Leg"] = (part.CFrame + (-RightVector+Vector3.new(0, -1+yOffset+r(5)/10, 0)))*CFrame.Angles(0, 0, rad(-r(10, 40))),
["Right Arm" ] = (part.CFrame + (RightVector+Vector3.new(0, 0+yOffset+r(5)/10, 0)))*CFrame.Angles(170, 0, rad(r(10, 50))),
["Right Leg"] = (part.CFrame + (RightVector+Vector3.new(0, -1+yOffset+r(5)/10, 0)))*CFrame.Angles(0, 0, rad(r(10, 40))),
["Torso"] = part.CFrame + Vector3.new(0, 0+yOffset+r(5)/10, 0)
}
return PartToCFrame[part.Name] --Return the CFrame of a part
end
local BodyParts = {}
task.delay(6.3, function() --Destroy all parts after 6.3 seconds, when the fade tween is finished
for _, part: Instance in pairs(BodyParts) do
part:Destroy()
end
end)
for _, item: Instance in ipairs(Character:GetDescendants()) do
if table.find(Parts, item.Name) then --Check if its a body part
local Clone: BasePart = item:Clone()
Clone:ClearAllChildren()
Clone.Anchored = true
Clone.CanCollide = false
Clone.Material = Enum.Material.Granite
Clone.Color = Color3.fromRGB(191, 0, 0)
Clone.Parent = workspace
BodyParts[Clone.Name] = Clone
end
if not item:IsA("Humanoid") then
item:Destroy()
end
end
if BodyParts["Head"] then
BodyParts["Head"].Size -= Vector3.new(1, 0, 0)
end
task.wait(0.3)
for _, part in pairs(BodyParts) do --Tween every part's CFrame
local FinalPos = GetCFrame(part)
if not FinalPos then continue end
local Tween = TweenService:Create(part, TweenInfo.new(2, Enum.EasingStyle.Sine), {CFrame = FinalPos})
Tween:Play()
end
task.wait(2)
for _, part: BasePart in pairs(BodyParts) do
part.Anchored = false
part.CanCollide = true
local Tween = TweenService:Create(part, TweenInfo.new(2, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 2), {Transparency = 1})
Tween:Play()
end
end)
Insert a RemoteEvent into the ReplicatedStorage:
And you’re done. I don’t know if this is exactly what you wanted.
Really like the idea. Keep up the good work!
Thank you for making this, this looks cool
Is there a way to make parts fly faster?
Of course! Just change some values. This code will make them fly 1 second faster.
I’ve also fixed a bug that prevented parts from being destroyed after fade tween was finished.
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
Players.RespawnTime = 4.3 --Change the respawn time so it'll fit the lengh of death effect. You can change the value, but you'll also need to change wait and tween times
local DeathRemote = ReplicatedStorage:WaitForChild("DeathRemote")
--Putting built-in functions into variables with short names saves space if called many times
local r = math.random
local rad = math.rad
local yOffset = 5 --How high will the parts fly
local Parts = {"Head", "Left Arm", "Left Leg", "Right Arm", "Right Leg", "Torso"}
DeathRemote.OnServerEvent:Connect(function(player) --Connect the event
local Character: Model = player.Character
if not Character then return end --Exit function and do nothing if there is no character
local function GetCFrame(part: BasePart): CFrame? --Put the function here so it'll generate new random values every time the event is fired
local RightVector = part.CFrame.RightVector
local PartToCFrame = {
["Head"] = part.CFrame + Vector3.new(0, 1+yOffset+r(5)/10, 0),
["Left Arm"] = (part.CFrame + (-RightVector+Vector3.new(0, 0+yOffset+r(5)/10, 0)))*CFrame.Angles(170, 0, rad(-r(10, 50))),
["Left Leg"] = (part.CFrame + (-RightVector+Vector3.new(0, -1+yOffset+r(5)/10, 0)))*CFrame.Angles(0, 0, rad(-r(10, 40))),
["Right Arm" ] = (part.CFrame + (RightVector+Vector3.new(0, 0+yOffset+r(5)/10, 0)))*CFrame.Angles(170, 0, rad(r(10, 50))),
["Right Leg"] = (part.CFrame + (RightVector+Vector3.new(0, -1+yOffset+r(5)/10, 0)))*CFrame.Angles(0, 0, rad(r(10, 40))),
["Torso"] = part.CFrame + Vector3.new(0, 0+yOffset+r(5)/10, 0)
}
return PartToCFrame[part.Name] --Return the CFrame of a part
end
local BodyParts = {}
task.delay(6.3, function() --Destroy all parts after 6.3 seconds, when the fade tween is finished
for _, part: Instance in pairs(BodyParts) do
part:Destroy()
end
end)
for _, item: Instance in ipairs(Character:GetDescendants()) do
if table.find(Parts, item.Name) then --Check if its a body part
local Clone: BasePart = item:Clone()
Clone:ClearAllChildren()
Clone.Anchored = true
Clone.CanCollide = false
Clone.Material = Enum.Material.Granite
Clone.Color = Color3.fromRGB(191, 0, 0)
Clone.Parent = workspace
BodyParts[Clone.Name] = Clone
end
if not item:IsA("Humanoid") then
item:Destroy()
end
end
if BodyParts["Head"] then
BodyParts["Head"].Size -= Vector3.new(1, 0, 0)
end
task.wait(0.3)
for _, part in pairs(BodyParts) do --Tween every part's CFrame
local FinalPos = GetCFrame(part)
if not FinalPos then continue end
local Tween = TweenService:Create(part, TweenInfo.new(2, Enum.EasingStyle.Sine), {CFrame = FinalPos})
Tween:Play()
end
task.wait(2)
for _, part: BasePart in pairs(BodyParts) do
part.Anchored = false
part.CanCollide = true
local Tween = TweenService:Create(part, TweenInfo.new(2, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 2), {Transparency = 1})
Tween:Play()
end
end)