I am making a raycasting turret but it won't work although the script has no errors The turret is supposed to shoot the bullet in ReplicatedStorage It should also turn to face the enemies too The turret doesn't move
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local bullet = ReplicatedStorage:WaitForChild("Bullet")
local turret = script.Parent
local fireRate = 0.5
local bulletDamage = 25
local bulletSpeed = 150
local aggroDist = 100
while wait(fireRate) do
end
--Find the target, detect if it's realistic to shoot
local target = nil
for i, v in pairs(game.Workspace:GetChildren()) do
local human = v:FindFirstChild("Humanoid")
local torso = v:FindFirstChild("Torso")
if human and torso and human.Health > 0 then
end
end
if (torso.Position - turret.Position).magnitude < aggroDist then
local bulletRay = Ray.new(turret.Position, (torso.Position - turret.Position).Unit * 500)
local hit, position = game.workspace:FindPartOnRayWithIgnoreList(bulletRay, {turret})
if hit == torso then
target = torso
else
print("Object in the way")
end
end
if target then
local torso = target
--Turn the turret to face the target
turret.CFrame = CFrame.new(turret.Position, torso.Position)
local newBullet = bullet:Clone()
newBullet.Postion = turret.Position
newBullet.Parent = game.Workspace
newBullet.Velocity = turret.CFrame.LookVector * bulletSpeed
newBullet.Touched:Connect(function(objectHit)
local human = objectHit.Parent:FindFirstChild("Humanoid")
if human then
human:TakeDamage(bulletDamage)
end
end)
end

2 comments
It doesn't shoot, or it doesn't even move? Please explain more.
The turret shoots but it doesn't move