Sword kill effect not working (need help)

I changed the original Roblox sword script and made it so that it would put a particle emitter into the set part of the player that dies from the sword.

But, it doesn’t work as intended.

local db = true

function Blow(Hit)
	if not Hit or not Hit.Parent or not CheckIfAlive() or not ToolEquipped then
		return
	end
	local RightArm = Character:FindFirstChild("Right Arm") or Character:FindFirstChild("RightHand")
	if not RightArm then
		return
	end
	local RightGrip = RightArm:FindFirstChild("RightGrip")
	if not RightGrip or (RightGrip.Part0 ~= Handle and RightGrip.Part1 ~= Handle) then
		return
	end
	local character = Hit.Parent
	if character == Character then
		return
	end
	
	if character:FindFirstChild("Humanoid").Health <= 0 then
		db = false
		local pe = game.Workspace.Part.Attachment.contrast
		pe.Parent = character.FindFirstChild("Torso")
		wait(1)
		db = true
	end
	
	local humanoid = character:FindFirstChildOfClass("Humanoid")
	if not humanoid or humanoid.Health == 0 then
		return
	end
	local player = Players:GetPlayerFromCharacter(character)
	if player and (player == Player or IsTeamMate(Player, player)) then
		return
	end
	UntagHumanoid(humanoid)
	TagHumanoid(humanoid, Player)
	humanoid:TakeDamage(Damage)	
end

This is the Hit part of the script, which in the “db” part, should insert a particle emitter into the player’s torso, and only play for a set amount of time.

(pe = ParticleEmitter, “contrast” is the particle)

Anything to change for it to work?

If contrast is the particle you gonna add to the torso, and seems like you only have one in Workspace, you should Clone() it, not just parent it, otherwise you would lose your particle after the first dead player

local pe = game.Workspace.Part.Attachment.contrast:Clone()
pe.Parent = character.FindFirstChild("Torso")

Add ways of debugging too

if game.Workspace.Part.Attachment:FindFirstChild("contrast") then
    warn("particle found")
else
    warn("no particle")
end

or this:

if character.FindFirstChild("Torso") then
    warn("theres actually a torso")
else
    warn("no torso found")
end

You mention nothing about the Output, theres no errors at all? you should put attention to Output console to see whats the error, to fix it

1 Like

Can you please be more specific about the error/problem encountered?

1 Like

This is the only thing I get now after a few fixes, but no particle shows up after killing the dummy/player

if character:FindFirstChild("Humanoid").Health <= 0 then
		db = false
		local pe = game.Workspace.Part.Attachment
		if game.Workspace.Part.Attachment:FindFirstChild("contrast") then
			pe:Clone()
			warn("particle found")
		else
			warn("no particle")
		end
		pe.Parent = character:FindFirstChild("Torso")
		if character:FindFirstChild("Torso") then
			warn("theres actually a torso")
		else
			warn("no torso found")
		end
		wait(1)
		db = true
	end

Not sure if this setup is correct either.

1 Like

The examples I gave you for debugging are not needed for the code to run, I was just giving examples on how you can find the issues by debugging.

Its not

local pe = game.Workspace.Part.Attachment
pe:Clone()

its:

local pe = game.Workspace.Part.Attachment.contrast:Clone()
pe.Parent = character.FindFirstChild("Torso")

Those lines, take the particle called “contrast”, Clone it, then store the clone into a variable called “pe”, now pe is the thing you want to parent to the Torso

1 Like

Scratch that, I forgot to enable the initial particle, therefore it shows up.

But, the reason it was disabled, is cause I wanted it to emit a certain amount of particles when the player is killed. (For example, look for the torso once, if it is found, stop looking for the torso, and emit x number of particles.)

1 Like

Enabled or not, you will lose the particle after the first kill. Its mandatory you clone it.

You have one particle, when Dummy dies, you take that particle place it in dummy torso, etc.
Torso is deleted because player died, particle in that torso is lost.
Next kill, your script looks for the particle, no particle at all, script fails

1 Like

Well, I got it to… sort of work.
It’s a bit random, sometimes it doesn’t make the particles work if I go past the torso too quickly, and it constantly emits if it hits the torso again, not sure how to make it a one-time thing, or only have a certain amount emitted at a time.

Or, in general, just making it so when the humanoid health is at 0, it only does specific tasks, not ones that can happen due to one thing, like freezing the player and making the particles emit with a count of 20.

if character:FindFirstChild("Humanoid").Health == 0 then
		local pe = game.Workspace.Part.Attachment.contrast:Clone()
		pe.Enabled = false
		if character:FindFirstChild("Torso") then
			pe.Parent = character:FindFirstChild("Torso")
			pe.Enabled = true
		wait(0.3)
			pe.Enabled = false
		end
	end
1 Like

Your code doesn’t support different avatar types.
Use the HumanoidRootPart instead, since it exists for every avatar regardless of the type.

1 Like

Thats not my code, what you mean?

1 Like

I’ll rephrase that, my bad!
You didn’t suggest using HumanoidRootPart is what I was trying to say.

2 Likes

Yeah, idk if OP has a specific setting in which reading Torso or whatever part works for OP, just adding debugs to OP’s script so can find the reason for the issue.
Ofc checking HRP its way better, but I think OP is looking for the solution of a different issue not exactly improving the code.
The issue its just the logic and implementation.

2 Likes