for some reason the ray is starting at script.Parent.HumanoidRootPart.Position and going towards handle.Position and stopping at handle.Position
function Shoot(TG)
if not db then
db = true
local params = RaycastParams.new()
params.IgnoreWater = true
params.FilterDescendantsInstances = {script.Parent,handle}
params.FilterType = Enum.RaycastFilterType.Exclude
local humanoid = TG:WaitForChild("Humanoid")
local RayCastResult = workspace:Raycast(handle.Position, (handle.Position - TG.HumanoidRootPart.Position).Unit * settings["Bullet_Range"],params)
if settings["Cast_Ray"] == true then
local bullet = Instance.new("Part")
bullet.Parent = workspace
bullet.BrickColor = BrickColor.new(settings["Bullet_Color"])
bullet.CanCollide = false
bullet.Name = "Bullet"
bullet.FormFactor = "Custom"
bullet.Anchored = true
bullet.BottomSurface = "Smooth"
bullet.TopSurface = "Smooth"
local center = handle.CFrame.p + (TG.HumanoidRootPart.Position - handle.CFrame.p).unit / 2
local distance = (TG.HumanoidRootPart.Position - handle.CFrame.p).Magnitude
bullet.Size = Vector3.new(0.2, 0.2, distance)
bullet.CFrame = CFrame.new(center, handle.CFrame.p)
game:GetService("Debris"):AddItem(bullet, settings["Time_Before_Bullet_Disappears"])
end
if RayCastResult ~= nil then
if RayCastResult.Instance.Parent:FindFirstChild("Humanoid") and RayCastResult.Instance:IsDescendantOf(workspace.Allies) or game.Players:GetPlayerFromCharacter(RayCastResult.Instance.Parent) then
RayCastResult.Instance.Parent.Humanoid:TakeDamage(settings["Damage"])
end
end
task.wait(settings["CoolDown"])
db = false
end
end