Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why is my backstab script not working? The NPC won't take damage, and the decal does not show up.

Hello. I have been trying to make a backstab system for my FPS game, but it wont work. The decal is not showing up and the NPC does not take any damage. Please help!

game.Players.PlayerAdded:Connect(function(plr)
	local BackstabPart = Instance.new("Part")
	local human = plr.Character
	BackstabPart.Transparency = 1
	BackstabPart.Parent = human
	BackstabPart.Position = human.Torso.Position
	BackstabPart.Anchored = true
	local BackstabWeld = Instance.new("Weld")
	BackstabWeld.Part0 = BackstabPart
	BackstabWeld.Part1 = human.Torso
end)

script.Parent.Activated:Connect(function()
	script.Parent.Handle.Touched:Connect(function(hit, BackstabPart)
		if hit == BackstabPart then
			if BackstabPart.Parent.Humanoid ~= nil then
				BackstabPart.Parent.Humanoid:TakeDamage(100)
				local blood = Instance.new("Decal")
				blood.Parent = BackstabPart.Parent.Torso
				blood.Face = "Back"
				blood.Texture = "rbxassetid://305296807"
			end
		end
	end)
end)

1 answer

✓ Accepted answer

The touched event only has 1 parameter, the "otherPart". or the other part that came in contact with the given part.

Also, you may want to make it so the person who is holding the part doesn't get stabbed.

script.Parent.Activated:Connect(
    function()
        script.Parent.Handle.Touched:Connect(
            function(BackstabPart)
                if BackstabPart.Parent == script.Parent.Parent then
                    if BackstabPart then
                        if BackstabPart.Parent:FindFirstChild("Humanoid") ~= nil then
                            BackstabPart.Parent.Humanoid:TakeDamage(100)
                            local blood = Instance.new("Decal")
                            blood.Parent = BackstabPart.Parent.Torso
                            blood.Face = "Back"
                            blood.Texture = "rbxassetid://305296807"
                        end
                    end
                end
            end
        )
    end
)

2 comments

0

Oh, okay. Thanks!

0

np

This discussion is preserved as it was. New answers, comments, and votes are closed.