Из того, что это звучит, вы хотите создать игру, в которой кирпичи получают урон при выстреле, но по какой-то причине они не получают урон. То, что я бы искал при отладке, это попытка ответить на следующие вопросы:
1) Пули появляются, когда и где я хочу их?
2) Пули движутся в правильном направлении?
3) Обнаружили ли кирпичи, что их коснулась пуля?
Ваш пример кода дает только подсказки по вопросам 1 и 2. Одной из проблем может быть то, что при расчете скорости пули вы отправляете пулю в направлении, которое вы не ожидаете.
Попробуйте что-то подобное в LocalScript, чтобы убедиться, что маркеры созданы и перемещены:
-- alias some variables to make it easier to find things
local fireButton = script.Parent -- <-- assumed that this is a button
local carWorkspace = script.Parent.Parent.Parent.Parent.Parent.Parent.Workspace
local car1 = carWorkspace.Car1
local machineGun = car1.Body.Weapons.MachineGun
-- create some constants for math stuff
local bulletSpeed = 30.0 -- <-- this is super slow so that we can test it
local counterGravityVect = Vector3.new(0, 93.2, 0) -- <-- this is witchcraft
-- make a helper for cloning bullets
local function createBullet(templateBullet, targetVector)
local newBullet = templateBullet:Clone()
newBullet.Transparency = 0
newBullet.Anchored = false
newBullet.Parent = game.Workspace
-- use a BodyForce instead of Velocity to propel the bullet
-- NOTE - there's no clear documentation about how much force you need
-- just mess with bulletSpeed until it moves fast enough for you
newBullet.Massless = true
local targetForce = BodyForce.new()
targetForce.Force = counterGravityVect + (targetVector * bulletSpeed)
targetForce.Parent = newBullet
return newBullet
end
function fireGun()
print("Gun fired, creating bullets...)
-- play the bang sounds
machineGun.Part1.Sound:Play()
machineGun.Part2.Sound:Play()
-- get the orientation of the machine gun
local targetVect = machineGun.CFrame.LookVector
-- spawn two new bullets and fire them
-- in the same direction as the machine gun
local b1 = createBullet(machineGun.bullet1, targetVect)
local b2 = createBullet(machineGun.bullet2, targetVect)
end
-- listen for mouse or touch input to the
fireButton.Activated:Connect(fireGun)
Но вы также должны убедиться, что ваши кирпичи получают урон при попадании. Вот простой способ сделать это:
1) Создать деталь
2) Добавить NumberValue как дочерний элемент
3) Добавьте скрипт к той части, которая выглядит следующим образом:
print("Hello world!- wall")
local wall = script.Parent
local health = wall.Health
local maxHealth = 10
-- top off the health
health.Value = maxHealth
-- add an event listener to the wall to make sure that it can get shot
wall.Touched:Connect(function(toucher)
print("Wall Touched ", toucher)
if (toucher.Name == "bullet") then
print("Got shot, losing health : ", health.Value - 1)
health.Value = health.Value - 1
toucher:Destroy()
if health.Value <= 0 then
wall:Destroy()
end
end
end)
Надеюсь, это несколько охватило основы того, что может пойти не так. Дайте мне знать, если что-то из этого не имеет смысла. Удачи!