Alright so i had this problem for some reason it says to attempt to index nil with “Health” (My limb system)
I try to make like when the raycast hit it will check if it had limbs folder and had humanoid if no limbs folder and had humanoid is for npcs, i tried like tries to use if not and if but its not working please help!!
local tool = script.Parent
local jamchance = 1
local SPREAD = 1000
--//Client\\--
tool.Fire.OnServerEvent:Connect(function(player, mouseHit)
if tool.Config.Ammo.Value <= 0 or tool.Config.Jammed.Value == true then
coroutine.wrap(function()
tool.Handle.Empty:Play()
end)()
elseif not tool.Config.Fired.Value == true and not tool.Config.Jammed.Value == true then
tool.Config.Ammo.Value -= 1
tool.Config.Fired.Value = true
--//RayCast\\--
local spreadPosition = Vector3.new(
tool.Handle.Attachment.WorldCFrame.Position.X + math.random(-SPREAD, SPREAD)/500,
tool.Handle.Attachment.WorldCFrame.Position.Y + math.random(-SPREAD, SPREAD)/500,
tool.Handle.Attachment.WorldCFrame.Position.Z + math.random(-SPREAD, SPREAD)/500
)
local ray = Ray.new(tool.Handle.Attachment.WorldPosition, (mouseHit.p - spreadPosition).unit * 300)
local hit, position, normal = game.Workspace:FindPartOnRay(ray, tool.Parent, false, true)
local distance = (position - tool.Handle.Attachment.WorldPosition).magnitude
local part = Instance.new("Part")
part.Anchored = true
part.CanCollide = false
part.Transparency = 1
part.BrickColor = BrickColor.new("Institutional white")
part.Material = Enum.Material.Neon
part.Size = Vector3.new(0.2, 0.2, distance)
part.CFrame = CFrame.new(position, tool.Handle.Attachment.WorldPosition) * CFrame.new(0, 0, -distance / 2)
part.Parent = workspace
--//Damage\\--
if hit then
if hit.Parent:FindFirstChild("Humanoid") then
if not hit.Parent:IsA("Accessory") or not hit.Name == "Handle" or not hit.Parent:IsA("Accoutrement") or not hit.Parent:IsA("Tool") then
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent:FindFirstChild("Limbs")then
local limb = hit.Name
if not hit.Parent.Limbs:FindFirstChild(limb).Health and hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Limbs:FindFirstChild(limb) then
return
else
hit.Parent.Limbs:FindFirstChild(limb).Health.Value -= script.Parent.Config.Limb.Value
hit.Parent:FindFirstChild("Humanoid"):TakeDamage(tool.Config.Damage.Value)
end
end
if hit.Parent:FindFirstChild("Humanoid") and not hit.Parent:FindFirstChild("Limbs") then
hit.Parent:FindFirstChild("Humanoid"):TakeDamage(tool.Config.Damage.Value)
end
end
end
end
--//Fire Animation\\--
local fire = script.Parent.Parent:WaitForChild("Humanoid"):LoadAnimation(script.Parent.Animations.Fire)
fire:Play()
--//Sounds\\--
tool.Handle.Fire:Play()
--//Particles\\--
for i,v in pairs(tool.Particles:GetChildren()) do
if v:IsA("ParticleEmitter") then
local particles = v:Clone()
particles.Parent = tool.Handle.Attachment
particles:Emit(10)
game.Debris:AddItem(particles,5)
end
end
--//Hole\\--
if hit then
if hit.Parent:FindFirstChild("Humanoid") then
local Hole = game.ReplicatedStorage.Hole2:Clone()
Hole.Parent = workspace
Hole.Position = mouseHit.p
local Weld = Instance.new("Weld")
Weld.Part0 = hit
Weld.Part1 = Hole
Weld.C0 = hit.CFrame:Inverse()
Weld.C1 = Hole.CFrame:Inverse()
Weld.Parent = Hole
game:GetService("Debris"):AddItem(Hole, 10)
else
local Hole = game.ReplicatedStorage.Hole:Clone()
Hole.Parent = workspace
Hole.Position = mouseHit.p
Hole.Size = Vector3.new(0.1,0.1,0.2)
Hole.CFrame = CFrame.new(position, position - normal)
local Weld = Instance.new("Weld")
Weld.Part0 = hit
Weld.Part1 = Hole
Weld.C0 = hit.CFrame:Inverse()
Weld.C1 = Hole.CFrame:Inverse()
Weld.Parent = Hole
game:GetService("Debris"):AddItem(Hole, 10)
end
end
--//Debris?\\--
game.Debris:AddItem(part, 0.02)
--//Cooldown\\--
wait(tool.Config.Cooldown.Value)
tool.Config.Fired.Value = false
--//Jam System\\--
local number = math.random(jamchance, 10)
if number == jamchance then
tool.Config.Jammed.Value = true
end
else
return
end
end)
tool.Bolt.OnServerEvent:Connect(function(player)
if tool.Config.Jammed.Value == true then
tool.Handle.Bolt:Play()
wait(0.5)
tool.Config.Jammed.Value = false
end
end)