How to fix Raycasting script not dealing damage ?
Theres not much to explain the title pretty much sums it up but heres the script
01 | function fireBullet(start, target, maxLength) |
03 | local directionVector = (target - start).unit |
04 | local direcitonCFrame = CFrame.new(start, start + directionVector) |
06 | local delta, lastTick, startTime = 0 , tick(), tick() |
07 | local hit, position, lastPosition = nil , target, start |
08 | local totalDistance = 0 |
15 | while not hit and totalDistance < maxLength do |
16 | delta = tick() - lastTick |
18 | local travelDistance = delta * gunset.mvelocity |
23 | travelDistance = travelDistance < 999 and travelDistance or 999 |
24 | totalDistance = totalDistance + travelDistance |
25 | local dropAmount = 9.81 / 2 * (tick() - startTime)^ 2 |
28 | CFrame.new( 0 , 0 , -totalDistance) - |
29 | Vector 3. new( 0 , dropAmount, 0 ) |
31 | local direction = CFrame.new(lastPosition, incremented.p).lookVector |
33 | local ray = Ray.new(lastPosition, direction * travelDistance) |
34 | local hit,pos,normal,material = workspace:FindPartOnRayWithIgnoreList(ray,ignore 2 ) |
36 | handleBulletHit(hit,pos,normal,material) |
39 | lastPosition = position |
43 | print ( "Distance maxed out, we hit nothing" ) |
48 | local handleBulletHit = function (hitPart, hitPoint, hitNormal,hitMaterial) |
51 | local humPart = character:FindFirstChild( "HumanoidRootPart" ) |
52 | local targetHumPart = hitPart.Parent:FindFirstChild( "HumanoidRootPart" ) |
53 | local hithumanoid = hitPart.Parent:FindFirstChild( "Humanoid" ) |
54 | if hithumanoid and targetHumPart and humPart and hithumanoid.Health > 0 then |
55 | if hitPart.Name = = "LeftLowerArm" or hitPart.Name = = "LeftUpperArm" or hitPart.Name = = "RightLowerArm" or hitPart.Name = = "RightUpperArm" then |
56 | remoteEvents.Hit:FireServer(hithumanoid,gunset.limbdamage,hitPart) |
57 | ApplyTags(hithumanoid) |
59 | remoteEvents.Hit:FireServer(hithumanoid,gunset.damage,hitPart) |
60 | ApplyTags(hithumanoid) |
63 | if not hithumanoid then |