local larm = script.Parent:FindFirstChild("HumanoidRootPart")
local rarm = script.Parent:FindFirstChild("HumanoidRootPart")
function findNearestTorso(pos)
local list = game.Workspace:children()
local torso = nil
local dist = 125
local temp = nil
local human = nil
local temp2 = nil
for x = 1, #list do
temp2 = list[x]
if (temp2.className == "Model") and (temp2 ~= script.Parent) then
temp = temp2:findFirstChild("HumanoidRootPart")
human = temp2:findFirstChild("Humanoid")
if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then
if (temp.Position - pos).magnitude < dist then
torso = temp
dist = (temp.Position - pos).magnitude
end
end
end
end
return torso
end
while true do
wait(math.random(0,0))
local target = findNearestTorso(script.Parent.HumanoidRootPart.Position)
if target ~= nil then
script.Parent.Humanoid:MoveTo(target.Position, target)
wait(5)
local char = script.Parent
local humanoid = char.Humanoid
local head = char.Head
for i = 1,6,1 do
if i == 1 then
script.Parent.laser.Transparency = 0.5
wait(0.5)
script.Parent.Humanoid.WalkSpeed = 0
wait(2)
script.Parent.laser.Transparency = 0
local damage_delay = 0.35
local damage = 5
local part = script.Parent.laser
local region = Region3.new(part.Position - (0.5 * part.Size), part.Position + (0.5 * part.Size))
while wait(damage_delay)
do
for _, part in pairs(workspace:FindPartsInRegion3(region, nil, math.huge))
do
if part.Name == "Right Leg" then
local human = part.Parent:FindFirstChild"Humanoid"
if script.Parent.laser.Transparency == 0 then
human.Health = human.Health - damage
end
end
end
end
else
script.Parent.laser.Transparency = 0.5
wait(0.5)
script.Parent.Humanoid.WalkSpeed = 0
wait(2)
script.Parent.laser.Transparency = 0
local damage_delay = 0.35
local damage = 5
local part = script.Parent.laser
local region = Region3.new(part.Position - (0.5 * part.Size), part.Position + (0.5 * part.Size))
while wait(damage_delay)
do
for _, part in pairs(workspace:FindPartsInRegion3(region, nil, math.huge))
do
if part.Name == "Left Leg" then
local human = part.Parent:FindFirstChild"Humanoid"
if human ~= nil then
if script.Parent.laser.Transparency == 0 then
human.Health = human.Health - damage
end
end
end
end
end
end
end
end
end
wait(2)
for i = 1,6,1 do
if i == 1 then
script.Parent.laser.Transparency = 1
script.Parent.Humanoid.WalkSpeed = 7
else
script.Parent.laser.Transparency = 1
script.Parent.Humanoid.WalkSpeed = 7
end
end
wait(2)
for i = 1,6,1 do
if i == 1 then
script.Parent.laser.Transparency = 1
script.Parent.Humanoid.WalkSpeed = 7
else
script.Parent.laser.Transparency = 1
script.Parent.Humanoid.WalkSpeed = 7
end
end
This is the lines of code that are not activating, Can anyone show me why? I want the part called laser to disappear after, but it isnt doing that.
