Hello Developers, I have a problem with this script, let me explain it first, it fires at a moving block, bullets chase after the block but still miss, why is that? I will show the script.
local ReplicationStorage = game:GetService("ReplicatedStorage")
local Bullet = ReplicationStorage:WaitForChild("Bullet")
local Turret = script.Parent
local fireRate = 0
local bulletDamage = 1
local bulletSpeed = 150
local aggroDistance = 1000
while wait(fireRate) do
local target = nil
for i, v in pairs(game.Workspace:GetChildren()) do
local aa = game.Workspace.MovingModel.Platform
if aa then
if (aa.Position - Turret.Position).magnitude < aggroDistance then
local bulletRay = Ray.new(Turret.Position, (aa.Position - Turret.Position).Unit * aggroDistance)
local hit, position = game.Workspace:FindPartOnRayWithIgnoreList(bulletRay, {Turret})
if hit == aa then
target = aa
end
end
end
end
if target then
local aa = target
Turret.CFrame = CFrame.new(Turret.Position, aa.Position)
local newBullet = Bullet:Clone()
newBullet.Position = Turret.Position
newBullet.Parent = game.Workspace
newBullet.Velocity = Turret.CFrame.LookVector * bulletSpeed * 8
newBullet.Touched:Connect(function(objectHit)
local aa = objectHit.Parent:FindFirstChild("Platform")
if aa then
print("hit")
end
end)
end
end
Is the problem that there is a miscalculation or is the velocity speed to slow or…? Any help is appreciated.