-
What do you want to achieve? i want the turret to fire at the target only when it is in its field of view
-
What is the issue? in the video
-
What solutions have you tried so far? I didn’t find anything useful on devforum
game:GetService("RunService").Heartbeat:Connect(function()
for _,v in pairs(workspace:GetChildren()) do
if v:FindFirstChildOfClass("Humanoid") ~= nil then
local character = v
local torso = character:FindFirstChild("Torso")
local humanoid = character:FindFirstChild("Humanoid")
if torso and humanoid.Health > 0 then
if (torso.Position - tool.TurretPart.Position).magnitude < MAX_DIST then
local rand = math.random(1,6)
if rand == 1 then
target = character:FindFirstChild("Torso")
elseif rand == 2 then
target = character:FindFirstChild("Head")
elseif rand == 3 then
target = character:FindFirstChild("Left Arm")
elseif rand == 4 then
target = character:FindFirstChild("Right Arm")
elseif rand == 5 then
target = character:FindFirstChild("Left Leg")
elseif rand == 6 then
target = character:FindFirstChild("Right Leg")
end
else
target = nil
end
end
end
end
if target then
firePoint.Light.Part.Color = Color3.fromRGB(0, 255, 0)
firePoint.Light.Part.PointLight.Color = Color3.fromRGB(0, 255, 0)
local torso = target
firePoint = tool.TurretPart
local target = {CFrame = CFrame.new(tool.TurretPart.Position, torso.Position)}
--tool.TurretPart.CFrame = CFrame.new(tool.TurretPart.Position, torso.Position)
local maked = tweenser:Create(tool.TurretPart,info,target)
maked:Play()
else
firePoint.Light.Part.Color = Color3.fromRGB(255, 0, 0)
firePoint.Light.Part.PointLight.Color = Color3.fromRGB(255, 0, 0)
end
wait(1)
end)
while wait(0.2) do
if target ~= nil then
local origin = firePoint.Position
--local direction = firePoint.WorldCFrame.LookVector.Unit
Fire(origin)
end
end