Hello forums, i am experiencing this issue lately and still didn’t know how to solve it yet. Basically, i want to make a limbs health script that add attribute to player’s part, the attribute value will be lowered when player take damage and eventually reach 0. I thought the script went well because it affect all parts which is what i wanted .However, the further i went, i start to notice the only part that was affected was the Left Arm part, it start from most of the time to all the time. I tried to fix it but i couldn’t. Any help to fix the script or optimizing it is appreciated! (There’s no error, i’ve fixed every error i could, Local script).
Here’s the script:
--- Prefering and setting:
local player = game:GetService("Players")
local char = player.LocalPlayer.Character
local humanoid = char:WaitForChild("Humanoid")
local OldHealth = humanoid.Health
local LArm = char:WaitForChild("Left Arm")
local originalLarmhp = 100
LArm:SetAttribute("Health", 100)
local RArm = char:WaitForChild("Right Arm")
local originalRarmhp = 100
RArm:SetAttribute("Health", 100)
local LLeg = char:WaitForChild("Left Leg")
local originallleghp = 100
LLeg:SetAttribute("Health", 100)
local RLeg = char:WaitForChild("Right Leg")
local originalRleghp = 100
RLeg:SetAttribute("Health", 100)
local Head = char:WaitForChild("Head")
local originalheadhp = 100
Head:SetAttribute("Health", 100)
local Torso = char:WaitForChild("Torso")
local originaltorsohp = 100
Torso:SetAttribute("Health", 100)
local chance = script.Chance
local dmg = script.Damage
--- Function
humanoid:GetPropertyChangedSignal("Health"):Connect(function()
if humanoid.Health < OldHealth then
if chance.Value == 1 then
LArm:SetAttribute("Health", originalLarmhp - dmg.Value)
if chance.Value == 2 then
RArm:SetAttribute("Health", originalRarmhp - dmg.Value)
if chance.Value == 3 then
LLeg:SetAttribute("Health", originallleghp - dmg.Value)
if chance.Value == 4 then
RLeg:SetAttribute("Health", originalRleghp - dmg.Value)
if chance.Value == 5 then
Head:SetAttribute("Health", originalheadhp - dmg.Value)
if chance.Value == 6 then
Torso:SetAttribute("Health", originaltorsohp - dmg.Value)
end
end
end
end
end
end
end
end)
--- randomizing the value.
while true do
wait(0.01)
chance.Value = math.random(0, 6)
dmg.Value = math.random(5, 25)
originalLarmhp = LArm:GetAttribute("Health")
originalRarmhp = RArm:GetAttribute("Health")
originallleghp = LLeg:GetAttribute("Health")
originalRleghp = RLeg:GetAttribute("Health")
originaltorsohp = Torso:GetAttribute("Health")
originalheadhp = Head:GetAttribute("Health")
end