the ray is supposed to shoot the noob npc but it goes in a completely different direction
local db = false
local settings = {
["Damage"] = 20;
["Bullet_Color"] = "New Yeller";
["Bullet_Range"] = 100; -- (In studs)
["Time_Before_Bullet_Disappears"] = .5;
["Cast_Ray"] = true;
["CoolDown"] = 1;
}
function Shoot(TG)
if not db then
db = true
local humanoid = TG:WaitForChild("Humanoid")
local collideRay = Ray.new(handle.CFrame.p, (handle.CFrame.p - TG.PrimaryPart.CFrame.p).unit * settings["Bullet_Range"])
local collidePart, positionPart = workspace:FindPartOnRay(collideRay, script.Parent, false, true)
local ignore = {script.Parent}
if collidePart then
if collidePart.CanCollide == false and collidePart.Parent then
if not collidePart.Parent:FindFirstChild("Humanoid") then
table.insert(ignore, collidePart)
end
end
end
local ray = Ray.new(handle.CFrame.p, (handle.Muzzel.WorldCFrame.p - TG.PrimaryPart.CFrame.p).unit * settings["Bullet_Range"])
local part, position = workspace:FindPartOnRayWithIgnoreList(ray, ignore, false, true)
if settings["Cast_Ray"] == true then
local bullet = Instance.new("Part",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 distance = (handle.CFrame.p - position).magnitude
bullet.Size = Vector3.new(0.2, 0.2, distance)
bullet.CFrame = CFrame.new(handle.Muzzel.WorldCFrame.p, position) * CFrame.new(0, 0, -distance / 2)
game:GetService("Debris"):AddItem(bullet, settings["Time_Before_Bullet_Disappears"])
end
if part ~= nil then
if part.Parent:FindFirstChild("Humanoid") and part.Parent.Parent == workspace.Allies or game.Players:GetPlayerFromCharacter(part.Parent) then
part.Parent.Humanoid:TakeDamage(settings["Damage"])
end
end
task.wait(settings["CoolDown"])
db = false
end
end
TG is the noob npc and handle is the gun that the other guy is holding and muzzel is an attachment inside the handle