The turrent is suppose to shoot the UpperTorso of anything with Humanoid, but the turrent part does not appear when tested. Instead every humanoid figure are pushed at the velocity of Bullet Speed - (1). Bullet in serverscript storage does not disappear during Test. Humanoid is pushed despite leaving the AggroDistance and no Bullet part could be seen fired.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Bullet = ReplicatedStorage:WaitForChild("Bullet")
local turrent = script.Parent
local Firerate = 2
local BulletDamage = 50
local BulletSpeed = 1
local AggroDistance = 50
while wait(Firerate)do
local target = nil
for i, v in pairs (game.Workspace:GetChildren()) do
local humanoid = v:FindFirstChild("Humanoid")
local UpperTorso = v:FindFirstChild("UpperTorso")
if humanoid and UpperTorso and humanoid.Health > 0 then
if (UpperTorso.Position - turrent.Position).magnitude < AggroDistance then
target = UpperTorso
end
end
end
if target then
local UpperTorso = target
turrent.CFrame = CFrame.new(turrent.Position, UpperTorso.Position)
local BulletClone = Bullet:Clone()
BulletClone.Position = turrent.Position
BulletClone.Parent = game.Workspace
BulletClone.Velocity = turrent.CFrame.LookVector * BulletSpeed
BulletClone.Touched:Connect(function(ThingHit)
local humanoid = ThingHit.Parent:FindFirstChild("Humanoid")
if humanoid then
humanoid:TakeDamage(BulletDamage)
end
end)
end
end
