Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago
Edited 3 years ago

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

Log in to vote
0
Answered by
raid6n 2196 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago

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
)

0
Oh, okay. Thanks! Coppper_Chase 9 — 3y
0
np raid6n 2196 — 3y
Ad

Answer this question