local aoe = workspace:GetPartsInPart(sphere)
for i, a in pairs(aoe) do
if a:IsA("BasePart") and a.Name ~= "HumanoidRootPart" then
if a:IsDescendantOf(workspace.NPCs) then
if a.Parent:FindFirstChildOfClass("Humanoid") then
if not table.find(targets, a.Parent) then
for i, d in pairs(a.Parent:GetDescendants()) do
if (d:IsA("BasePart") or d:IsA("Decal") and d.Name ~= "HumanoidRootPart") then
local tween = tweenservice:Create(d, tweeninfo, {Transparency = 1})
tween:Play()
elseif d:IsA("BillboardGui") then
d.Enabled = false
end
table.insert(targets, a.Parent)
print("STARTED NPC")
end
end
wait(10)
if table.find(targets, a.Parent) then
for i, d in pairs(a.Parent:GetDescendants()) do
if (d:IsA("BasePart") or d:IsA("Decal") and d.Name ~= "HumanoidRootPart") then
local tween = tweenservice:Create(d, tweeninfo, {Transparency = 0})
tween:Play()
elseif d:IsA("BillboardGui") then
d.Enabled = true
end
local newtween = tweenservice:Create(sphere, tweeninfo, {Size = Vector3.new(0, 0, 0), Transparency = 1})
newtween:Play()
newtween.Completed:Wait()
sphere:Destroy()
print("ENDED NPC")
end
end
end
elseif a:IsDescendantOf(workspace.Players) then
if a.Parent:FindFirstChildOfClass("Humanoid") then
if not table.find(targets, a.Parent) then
local player = game.Players:GetPlayerFromCharacter(a.Parent)
for i, d in pairs(a.Parent:GetDescendants()) do
if (d:IsA("BasePart") or d:IsA("Decal") and d.Name ~= "HumanoidRootPart") then
local tween = tweenservice:Create(d, tweeninfo, {Transparency = 1})
tween:Play()
remote:InvokeClient(player, 0.7)
elseif d:IsA("BillboardGui") then
d.Enabled = false
end
table.insert(targets, a.Parent)
print("STARTED PLAYER")
end
end
wait(10)
if table.find(targets, a.Parent) then
for i, d in pairs(a.Parent:GetDescendants()) do
if (d:IsA("BasePart") or d:IsA("Decal") and d.Name ~= "HumanoidRootPart") then
local tween = tweenservice:Create(d, tweeninfo, {Transparency = 0})
tween:Play()
elseif d:IsA("BillboardGui") then
d.Enabled = true
end
local newtween = tweenservice:Create(sphere, tweeninfo, {Size = Vector3.new(0, 0, 0), Transparency = 1})
newtween:Play()
newtween.Completed:Wait()
sphere:Destroy()
print("ENDED PLAYER")
end
end
end
end
end
end
I want it so it only inserts into the table once and print it once, not 100+ times.
Any solution?
Where would I put that if statement? I want it to print “STARTED NPC” if it’s an npc and not a player.
local debounce = false
local aoe = workspace:GetPartsInPart(sphere)
--[[ if debounce == false then
debounce = true
print("STARTED NPC")
end ]]
for i, a in pairs(aoe) do
if a:IsA("BasePart") and a.Name ~= "HumanoidRootPart" then
if a:IsDescendantOf(workspace.NPCs) then
if a.Parent:FindFirstChildOfClass("Humanoid") then
if not table.find(targets, a.Parent) then
for i, d in pairs(a.Parent:GetDescendants()) do
if (d:IsA("BasePart") or d:IsA("Decal") and d.Name ~= "HumanoidRootPart") then
local tween = tweenservice:Create(d, tweeninfo, {Transparency = 1})
tween:Play()
elseif d:IsA("BillboardGui") then
d.Enabled = false
end
table.insert(targets, a.Parent)
print("STARTED NPC")
end
end
wait(10)
if table.find(targets, a.Parent) then
for i, d in pairs(a.Parent:GetDescendants()) do
if (d:IsA("BasePart") or d:IsA("Decal") and d.Name ~= "HumanoidRootPart") then
local tween = tweenservice:Create(d, tweeninfo, {Transparency = 0})
tween:Play()
elseif d:IsA("BillboardGui") then
d.Enabled = true
end
local newtween = tweenservice:Create(sphere, tweeninfo, {Size = Vector3.new(0, 0, 0), Transparency = 1})
newtween:Play()
newtween.Completed:Wait()
sphere:Destroy()
print("ENDED NPC")
end
end
end
elseif a:IsDescendantOf(workspace.Players) then
if a.Parent:FindFirstChildOfClass("Humanoid") then
if not table.find(targets, a.Parent) then
local player = game.Players:GetPlayerFromCharacter(a.Parent)
for i, d in pairs(a.Parent:GetDescendants()) do
if (d:IsA("BasePart") or d:IsA("Decal") and d.Name ~= "HumanoidRootPart") then
local tween = tweenservice:Create(d, tweeninfo, {Transparency = 1})
tween:Play()
remote:InvokeClient(player, 0.7)
elseif d:IsA("BillboardGui") then
d.Enabled = false
end
table.insert(targets, a.Parent)
print("STARTED PLAYER")
end
end
wait(10)
if table.find(targets, a.Parent) then
for i, d in pairs(a.Parent:GetDescendants()) do
if (d:IsA("BasePart") or d:IsA("Decal") and d.Name ~= "HumanoidRootPart") then
local tween = tweenservice:Create(d, tweeninfo, {Transparency = 0})
tween:Play()
elseif d:IsA("BillboardGui") then
d.Enabled = true
end
local newtween = tweenservice:Create(sphere, tweeninfo, {Size = Vector3.new(0, 0, 0), Transparency = 1})
newtween:Play()
newtween.Completed:Wait()
sphere:Destroy()
print("ENDED PLAYER")
end
end
end
end
end
end
I also have another problem, when you do the move, it doesn’t set the characters inside’s parts transparency to 1 again since they were probably in the table. (it also doesnt print the started and ended thingy)