Use for loops to change every part’s transparency.
Example:
for _, Object in ipairs(NPC:GetChildren()) do
if Object:IsA("BasePart") then
Object.Transparency = 0.5
end
end
This is what it should look like in your script:
local Npc = script.Parent
function ChangeTransparency(Transparency)
for i, Object in ipairs(Npc:GetChildren()) do
if Object:IsA("BasePart") then
Object.Transparency = Transparency
end
end
end
while task.wait(1) do
ChangeTransparency(0.4)
task.wait(1)
ChangeTransparency(1)
task.wait(1)
ChangeTransparency(0.4)
task.wait(1)
ChangeTransparency(0)
end
If you want to use tweens to make it look smooth it’ll look like this:
local Npc = script.Parent
local TweenService = game:GetService("TweenService")
local Speed = 1
function ChangeTransparency(Transparency)
for i, Object in ipairs(Npc:GetChildren()) do
if Object:IsA("BasePart") then
TweenService:Create(Object, TweenInfo.new(Speed), {Transparency = Transparency}):Play()
end
end
end
while task.wait(1) do
ChangeTransparency(1)
task.wait(1)
ChangeTransparency(0)
end
If you want to make the NPC invisible, use something that’s called a for loop
What this loop does, is it basically goes through an Array (Or group of objects) and you can check to see if those Objects would be BaseParts
Humanoid Instances don’t have a Transparency property, and additionally you can create a custom Number variable to check how transparent you want to make the NPC
local NPC = workspace:WaitForChild("TeddyAI")
local Visibility = 0 -- 0 is visible, 1 is invisible
while true do
wait(1)
if Visibility == 0 then
Visibility = 1
else
Visibility = 0
end
for _, Part in pairs(NPC:GetChildren()) do
if Part:IsA("BasePart") then
Part.Transparency = Visiblity
end
end
end