I’m trying to make a dynamic bone life indicator using color to represent the health.
When i try to run the code, it sometimes says this : invalid argument #2 (string expected, got Color3). The code use : v[v.Color] where v is the looped part and the second v is to reference the bone which has the same name as v(Instance) and is a child of v.
I tried looking in the dev hub but there where nothing.
local Childrens = script.Parent:GetDescendants()
local MinForce = 25
local BoneMinForce = 30
local Parts = {}
for i, v in pairs(Childrens) do
if v:IsA("PVInstance") and not v:IsA("Model") and v.Name ~= "HumanoidRootPart" then
Parts[v] = {500, 1000}
v.Touched:Connect(function(Hit)
local AppliedForce = Vector3.new(math.abs(Hit.AssemblyLinearVelocity.X - v.AssemblyLinearVelocity.X), math.abs(Hit.AssemblyLinearVelocity.Y - v.AssemblyLinearVelocity.Y), math.abs(Hit.AssemblyLinearVelocity.Z - v.AssemblyLinearVelocity.Z))
if AppliedForce.X >= MinForce or AppliedForce.Y >= MinForce or AppliedForce.Z >= MinForce then
local df = Vector3.new(Hit.Position.Z - v.Position.Z, Hit.Position.Y - v.Position.Y, Hit.Position.X - v.Position.X).Unit
local Normal = math.acos((Hit.Position:Dot(df)) / (Hit.Position.Magnitude * df.Magnitude))
local Side = Vector3.FromNormalId(Normal)
AppliedForce = (AppliedForce.X * Side.Z) + (AppliedForce.Y * Side.Y) + (AppliedForce.Z * Side.X)
if AppliedForce >= MinForce then
local AppliedStress = AppliedForce * AppliedForce / 5
Parts[v][1] -= AppliedStress
if AppliedForce >= BoneMinForce then
local AppliedStress = AppliedForce * AppliedForce / 2
Parts[v][2] -= AppliedStress
--Error at v[v.Color] ---> v[v] = v[v.Color]:Lerp(Color3.fromRGB(196, 40, 28), (1000 - Parts[v][2]) * 100 / 500 / 500)
end
v.Color = v.Color:Lerp(Color3.fromRGB(196, 40, 28), (500 - Parts[v][1]) * 100 / 500 / 500)
if Parts[v][1] <= 0 then
local D = v:Clone()
D.Parent = workspace
v:Destroy()
local Sound = script.Limb:Clone()
Sound.Parent = v
Sound.Playing = true
end
end
end
end)
end
end
I really confused about why it is doing that so it would be great someone found a fix.