#Why bullet's orientation dont change

3 messages · Page 1 of 1 (latest)

tepid cloak
#

local npc = script.Parent
local humanoidRootPart = npc:WaitForChild("HumanoidRootPart")
local gun = npc:WaitForChild("Gun") -- Зброя (частина)
local range = 50 -- Дистанція стрільби
local damage = 10 -- Кількість шкоди
local cooldown = 1 -- Затримка між пострілами

local bulletSize = Vector3.new(1, 1, 1) -- Розмір кулі
local bulletSpeed = 50 -- Швидкість кулі (чим менше, тим довше в повітрі)
local bulletLifespan = 10 -- Час існування кулі
local bulletMeshId = "rbxassetid://16231432533" -- Вставте ID вашого Mesh тут

local function findClosestPlayer()
local closestPlayer = nil
local shortestDistance = range

for _, player in pairs(game.Players:GetPlayers()) do
    if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
        local playerRootPart = player.Character.HumanoidRootPart
        local distance = (playerRootPart.Position - humanoidRootPart.Position).Magnitude
        if distance <= shortestDistance then
            closestPlayer = player
            shortestDistance = distance
        end
    end
end

return closestPlayer

end

local function shootAtPlayer(target)
local bullet = Instance.new("Part")
bullet.Size = bulletSize -- Розмір кулі
bullet.Shape = Enum.PartType.Ball
bullet.BrickColor = BrickColor.new("Bright red")
bullet.Anchored = false
bullet.CanCollide = false
bullet.CFrame = gun.CFrame

-- Додаємо Mesh до кулі
local mesh = Instance.new("SpecialMesh")
mesh.MeshId = bulletMeshId  -- Присвоюємо Mesh
mesh.Parent = bullet

bullet.Parent = workspace

-- Замість того, щоб стріляти в HumanoidRootPart, цільсямо в голову
local head = target.Parent:FindFirstChild("Head")  -- Пошук голови
local direction
#

Second part:

#
local humanoidRootPart = npc:WaitForChild("HumanoidRootPart")
local gun = npc:WaitForChild("Gun") -- Зброя (частина)
local range = 50 -- Дистанція стрільби
local damage = 10 -- Кількість шкоди
local cooldown = 1 -- Затримка між пострілами

local bulletSize = Vector3.new(1, 1, 1) -- Розмір кулі
local bulletSpeed = 50 -- Швидкість кулі (чим менше, тим довше в повітрі)
local bulletLifespan = 10 -- Час існування кулі
local bulletMeshId = "rbxassetid://16231432533"  -- Вставте ID вашого Mesh тут

local function findClosestPlayer()
    local closestPlayer = nil
    local shortestDistance = range

    for _, player in pairs(game.Players:GetPlayers()) do
        if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
            local playerRootPart = player.Character.HumanoidRootPart
            local distance = (playerRootPart.Position - humanoidRootPart.Position).Magnitude
            if distance <= shortestDistance then
                closestPlayer = player
                shortestDistance = distance
            end
        end
    end

    return closestPlayer
end

local function shootAtPlayer(target)
    local bullet = Instance.new("Part")
    bullet.Size = bulletSize -- Розмір кулі
    bullet.Shape = Enum.PartType.Ball
    bullet.BrickColor = BrickColor.new("Bright red")
    bullet.Anchored = false
    bullet.CanCollide = false
    bullet.CFrame = gun.CFrame

    -- Додаємо Mesh до кулі
    local mesh = Instance.new("SpecialMesh")
    mesh.MeshId = bulletMeshId  -- Присвоюємо Mesh
    mesh.Parent = bullet

    bullet.Parent = workspace

    -- Замість того, щоб стріляти в HumanoidRootPart, цільсямо в голову
    local head = target.Parent:FindFirstChild("Head")  -- Пошук голови
    local direction