It's a local script inside a tool (the tool has a handle also), inside the starterpack. I made it so that if you shot someone's torso or head it would do 50 damage, and if you shot someone's legs or arms it would do 25 damage. I tested it on dummies containing humanoids that have 100 health, and my gun would always do 50 damage. Whether I shot the head, torso, arms, legs, it would always do 50 damage, no matter what! So what did I do wrong here, and how do I fix it? This is the script:
local tool = script.Parent
local player = game:GetService("Players").LocalPlayer
tool.Equipped:connect(function(mouse)
mouse.Button1Down:connect(function()
local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit * 50)
local part, position = workspace:FindPartOnRay(ray, player.Character, false, true)
local beam = Instance.new("Part", workspace)
beam.BrickColor = BrickColor.new("Black")
beam.FormFactor = "Custom"
beam.Material = "SmoothPlastic"
beam.Transparency = 0.25
beam.Anchored = true
beam.Locked = true
beam.CanCollide = false
local distance = (tool.Handle.CFrame.p - position).magnitude
beam.Size = Vector3.new(0.3, 0.3, distance)
beam.CFrame = CFrame.new(tool.Handle.CFrame.p, position) * CFrame.new(0, 0, -distance / 2)
game:GetService("Debris"):AddItem(beam, 0.1)
if part then
local humanoid = part.Parent:FindFirstChild("Humanoid")
if not humanoid then
humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
end
if humanoid.Torso or humanoid.Head then
humanoid:TakeDamage(50)
elseif humanoid.RightArm or humanoid.LeftArm or humanoid.RightLeg or humanoid.LeftLeg then
humanoid:TakeDamage(25)
end
end
end)
end)

1 comment
line 32: humanoid:TakeDamage(100) -- not 50