Sword kill effect script

I am currently trying to make a kill effect with a sword for my sword fighting game.

I figured out a way to make up a script that causes a custom death effect, when resetting or being killed by something like a kill block.

I am trying to figure out how to make it so that custom death effect is caused when you kill someone with a certain sword, rather than resetting.

Screen Shot 2021-04-18 at 2.31.57 PM


How can I make it so this script only applies to the weapon/sword you hold?

1 Like

You can check if the tool that it applies to is in the players character. When a tool is equipped it parents to the players character.

The script currently doesn’t have a part that applies the script to any tool, or the one I’m using.

Further reading your post, the custom death effect should work if killed by the sword. Make sure your using a server script to take the players health.

I can confirm it does trigger the effect when a different player is killed in ANY way. But, since I will create different scripts for multiple swords, there would need to be a way to apply the script to a single sword, and then a different script applied to a different sword, and so on.

You could add something to your sword script that checks if the players health is 0 then it triggers the respective effect.


Is the highlighted script a valid part to check if the health is 0?

That just checks if it exists. Humanoid.Health is what you should check.

I do see 1 major thing with this:

You’re literally using a ton of for loops, when in all reality you can literally encase it in 1 entire loop since you’re only getting the Character’s Children

script.Parent:WaitForChild("Humanoid").Died:Connect(function()
    local Effect
    
    for i, v in pairs(script.Parent:GetChildren()) do
        if v:IsA("BasePart") then
        end

        if v:IsA("Shirt") or v:IsA("Pants") or v:IsA("Accessory") or v:IsA("Decal") then
            v:Destroy()
        end

        if v:IsA("BasePart") then
            v.Anchored = true
            Effect = script.Particles:Clone()
            Effect.Parent = v
            v.BrickColor = BrickColor.new("Maroon")
            v.Transparency = 0
            wait() --This is there just to refer to the OP's post, I will change this to RunService.Heartbeat if necessary
        end
    end
    Effect.Enabled = true
    wait(1)
    Effect.Enabled = false
end)

Also if you want to detect when you kill someone with a sword, use CreatorTags for those to check when a target dies by the killer

Also please format your code in code blocks

I am using a Classic Sword from ROBLOX, which I modified, and the SwordScript in it has a creator tag. The current script I am showing is coming after that.
Screen Shot 2021-04-18 at 3.32.03 PM

But nothing happens when killing a player with the sword.

I think the best way to do this is with a module.
Make a module and add some function keys with the sword’s name to it which makes it easily customizable and have an initializing function that checks the held sword and sees if the held sword’s name is the same as a function in the table.