Kill effect script

I was attempting to make a kill effect happen when for example, a player’s sword kills a player/humanoid, for my game. I had a few issues, mostly the script not working.

Here are the screenshots of the scripts:
Screen Shot 2021-04-18 at 2.07.10 AM

The next script:
Screen Shot 2021-04-18 at 2.07.43 AM

This was the scripts I fixed a bit ago, and they still didn’t work.

Any sort of fix for these would be a big help!

Thanks!! :smile:

Is there another script called KillEffect in StarterCharacterScripts? Or is it just the one in sword?

Also, turning disabled off no longer restarts the script (correct me if I’m wrong)

You should consider using ModuleScript (roblox.com) instead

Can you give more info? (errors, entire scripts, what exactly doesn’t work)

1 Like

The KillEffect script is part of the sword, and the other Script is in the SCS folder

image
What are you trying to do here!?

image
I’m unsure about this one but maybe the “WaitForChild” function is causing an infinite yield?

EDIT: I’m unsure about the second script then, maybe “KillEffect” doesn’t exist and no error is shown due to the “if” statement.

1 Like

But in your code, you FindFirstChild in Humanoid, tools are in the Character when loaded.

Also, you can’t ensure that player has their sword equipped all the time

Try including the code from KillEffect into your script

The secondary code is for the SCS script, which should be contained within the character, so no infinite yields should be occurring. (unless there is an error)

I’m unsure about the second script then, maybe “KillEffect” doesn’t exist and no error is shown due to the “if” statement.

1 Like

I have a theory that maybe SwordScript dumps its contents into the victim’s Humanoid? But that’s just a guess, we have no confirmation since we don’t know what’s in SwordScript

2 Likes

The SwordScript is the script shown from the free model from ROBLOX, of the default sword. I added onto it.

Which though? Can you give us a link? Because some swords are different that others. So it would be helpful if you gave us a specific one.

Also, when you run it and kill someone with it, does it put KillScript in their Humanoid?

(I think I found it: Sword)

Are there any errors being shown? if not, remove the “if” statement from this script and check again?

The SCS script should look like this after removing the “if” statement:

local Humanoid = script.Parent:WaitForChild("Humanoid")

Humanoid.Died:Connect(function()
    Humanoid.KillEffect.Disabled = false
end)

EDIT: Can you link the sword?

That was the model I used for my sword

Did you modify the code yourself? Because KillScript isn’t going into the victim’s character.

Try putting the code directly into your SCS script

e.g.

local Humanoid = script.Parent:WaitForChild("Humanoid")
local character = script.Parent

Humanoid.Died:Connect(function()
	for _,v in pairs(character:GetChildren()) do -- Code added here
		if v:IsA("BasePart") or v:IsA("Accessory") then
			v:Destroy()
		end
	end -- End of added code
end)

My main objective was to make it so the character disappears when killed, putting the code directly now fixes it!

2 Likes

Is there any way this can be set to be used for an individual sword? For example, one sword kills the player, and they disappear. The other sword (without the script) doesn’t make the player disappear.

Wrap the disappear script in an “if” statement.

local Disappear = true --at the top of your script, you can change this value

Humanoid.Died:Connect(function()
        if Disappear == true then
            for _, v in pairs(character:GetChildren()) do
                if v:IsA("BasePart") or v:IsA("Accessory") then
                    v:Destroy()
                end
            end
        end
    end)