Basicly I am trying to make one tool kill effect. (When you kill someone with the tool one animation starts on your enemy and you will see one ParticleEmitter on the enemy HumanoidRootPart)
I dont know how I cant play the animation on the other player character but I can clone Particles on it (HumanoidRootPart.Position)
I did some tests and they look like this
GIF:
local tool = script.Parent
local CanAttack = true
local hitCharacters = {}
local debounce = false
local hitSound = tool:WaitForChild("HitSound")
local killThing = game.ReplicatedStorage.TestKill
local LocalPlayer = game:GetService("Players").LocalPlayer
tool.Activated:Connect(function()
local humanoid = script.Parent.Parent:FindFirstChild("Humanoid")
if not debounce then
debounce = true
tool.Blade.Touched:Connect(function(touch)
if hitCharacters[touch.Parent] or not debounce then return end
if touch.Parent:FindFirstChild("Humanoid") then
if touch.Name == "Head" then
touch.Parent.Humanoid:TakeDamage(30)
hitSound:Play()
elseif touch.Name == "HumanoidRootPart" then
touch.Parent.Humanoid:TakeDamage(50)
hitSound:Play()
else
touch.Parent.Humanoid:TakeDamage(25)
hitSound:Play()
end
hitCharacters[touch.Parent] = true
wait(0.5)
hitCharacters[touch.Parent] = nil
debounce = false
end
end)
end
end)
--------------------------- here the kill effect function------------------------------
tool.Blade.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Humanoid.Health <= 0 then
-------------------------------------------------------- this part works
local character = hit.Parent
local humanoid = character.Humanoid
humanoid.BreakJointsOnDeath = false
local humanoidRootPart = character.HumanoidRootPart
print("test")
local newKillThing = killThing:Clone()
newKillThing .Parent = humanoidRootPart
newKillThing .Position = humanoidRootPart.Position
--------------------------------------------------------
-------------------------------------------------------- this part Idk how I can make
local animation = script:WaitForChild("Died") -- animation
local animationTrack = humanoid:LoadAnimation(animation)
animationTrack:Play()
end
end)
----------------------------------------------------------------------------------------
Humanoids need to have at least 1HP to play the animation (aka not dead).
set the tool so it doesn’t drop the humanoid health to less than 1HP and write down a function that triggers the animation when the humanoid health is set to 1, then set it to 0 at the end of your animation.
You can set a variable when when the tool touchs the enemy and check if the enemy has humanoid, after that you will check if the the humanoid has 1HP, if so then you can create new animation, and load it in the other humanoid like this
local tool = script.Parent
local Handle = tool.Handle
Handle.Touched:Connect(function(hit)
local h = hit.Parent:FindFirstChild("Humanoid")
if h then
if h.Health ==1 then
local anim = Instance.new("Animation")
anim.AnimationId = "Your id here"
local playAnim = h:LoadAnimation(anim)
playAnim:Play()
end
end
end)
If there is any error then don’t hesitate to inform me
EDIT: You should put it inside a normal script inside the tool
I’m New to Lua. Is that h car the other player and then when touched connected the function with the statement to load anim for them by touch association? I’ve been having trouble to loading “other” players in scripts
Look, it is like when you make sword that hurts the other humanoid when touched, you set a variable called “h” or “Humanoid” if the other humanoid touched the blade of the sword. Then you start to write the script that will decrease the health of the humanoid. Same as here, you set a variable called “h” (Or if you want you can name it “Humanoid”) and then check if it is available, after that you play the animation by writing the LoadAnimation script (If you were experienced in making animations, you will know what I mean).
I don’t see why you need to do that but…
Yes, you can.
You’ll have to get the parent of the part that got touched by the tool, then clone the animation and put it inside the humanoid.
It’ll be something like:
Tool.Handel.Touched:connect(function (hit)
If hit.name == "humanoidRootPart" then
Local Ani = Animation:Clone()
Ani.Parent = hit.Parent.Humanoid
end
end)
I change the animation parent to the humanoid then I play the animation?
Nvm its done:
tool.Blade.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Humanoid.Health <= 0 then
local character = hit.Parent
local humanoid = character.Humanoid
humanoid.BreakJointsOnDeath = false
humanoid.Died:Connect(function()
local torso = character.Torso
local humanoidRootPart = character.HumanoidRootPart
humanoidRootPart.Anchored = true
local newKillThing = killThing:Clone()
newKillThing.Parent = torso
newKillThing.Position = torso.Position
local Ani = script.Died:Clone()
Ani.Parent = hit.Parent.Humanoid
local playAni = humanoid:LoadAnimation(Ani)
playAni:Play()
print("test")
debounce = false
end)
end
end)
Btw how I can make the character stop moving for he dont move while the animation play?
Edit: Use humanoid.Died:Connect(function() for dont clone multiple the animation or the “newKillThing”