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

How to code specific damage Script on a part?

Asked by 6 years ago

Let's say a player touches a part and he touched it with it "Right Arm" or "Left Leg", how would I code something that detects that part of his/her body that it touches and gives a certain amount of damage?

0
well im not really sure but wouldnt they have to have humanoids and then you just find it in there? The_Pr0fessor 595 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Parent an IntValue or NumberValue in the part and subtract a value from it on collision.

--Script
game.Players.PlayerAdded:connect(function(ply)
    ply.CharacterAdded:connect(function(cha)
        local hum = cha:WaitForChild("Humanoid")
        local parts = {
            ["Right Arm"] = 5,  --R6
            ["Left Arm"] = 5,   
            ["LeftLowerArm"] = 5,   --R15
            ["LeftUpperArm"] = 5,
            ["RightLowerArm"] = 5,
            ["RightUpperArm"] = 5,
            ["RightHand"] = 2,
            ["LeftHand"] =2
        }
        for I,v in pairs(cha:GetChildren()) do
            if parts[v.Name] then
                local hp = Instance.new("IntValue",v)
                hp.Name = "Health"
                hp.Value = parts[v.Name]
            end
        end
    end)
end)

--Part that Touches character script

local damage = 5

script.Parent.Touched:connect(function(hit)
    local par = hit.Parent
    if par.ClassName == "Model" then
        local hp = hit:FindFirstChild("Health")
        if hp then
            hp.Value = hp.Value - damage
            if hp.Value <=0 then
                hit:Destroy()
            end
        end
    end
end)
Ad

Answer this question