So i wanted to make something and I have also followed a tutorial however it is not working and everything i do to it wont fix it and another thing is the while wait() do loop is only playing once and i am also not getting any errors in output.
local turret = script.Parent
local bulletdamage = 15
local bulletspeed = 150
local aggrodist = 75
local firerate = .3
local bullet = game.ReplicatedStorage:WaitForChild("Bullet")
while wait(firerate) do
print("Checking")
local target = nil
for i,v in pairs(game.Workspace:GetChildren()) do
local human = v:WaitForChild("Humanoid")
local root = v:WaitForChild("HumanoidRootPart")
if human and root and human.Health > 0 then
if (root.Position - turret.Position).magnitude < aggrodist then
target = root
end
end
end
if target then
local root = target
turret.CFrame = CFrame.new(turret.Position, root.Position)
local NewBullet = bullet:Clone()
NewBullet.Parent = workspace
NewBullet.Position = turret.Position
NewBullet.Velocity = turret.CFrame.LookVector * bulletspeed
NewBullet.Touched:Connect(function(hit)
local hum = hit.Parent:WaitForChild("Humanoid")
if hum then
hum:TakeDamage(bulletdamage)
NewBullet:Destroy()
elseif hit ~= turret then
NewBullet:Destroy()
end
end)
end
end

4 comments
i think its a problem with the for i,v in pairs(game.Workspace:GetChildren()) do since after that line you have one that waits for a humanoid. what if V is some random part in the workspace? the script would stop there untill you add a humanoid into that.
to test this can you put a print(v.Name) right after the for i,v in pairs(game.Workspace:GetChildren()) do line. then tell me what is prints.
It printed 'Camera' so I should probably do something like if v.Name ~= "Camera" or something like that.
Ok so it didnt print camera this time but it printed Baseplate so i should find a way to use something like :IsA() or something like that