Hey, In this script im basically just switching parts from visible to invisible depending on what type of tag they have on their part/model. (Real vs Dream), However… The root part on models will not go invisible, and that is a problem ![]()
VIDEO: [Gyazo link]
https://gyazo.com/a88a25ed51693c376cbd405edf0e6abe
Long script first, and then the questionable part of the script that i’ll be talking about specifically.
-- Variables
local debounce = false
local dreaming = false
-- Service Fetch
local UIS = game:GetService("UserInputService")
local rs = game:GetService("ReplicatedStorage")
-- Misc Variables
local player = game.Players.LocalPlayer
local frame = script.Parent.RealityMarker
local Lighting = game.Lighting:GetChildren()
local PresentLighting = rs:FindFirstChild("Present")
local PastLighting = rs:FindFirstChild("Past")
local SongPast = workspace.Audios.OneiroPast
local SongPresent = workspace.Audios.OneiroPresent
local SongCicada = workspace.Audios.Cicada
SongPresent:Play()
local PastParticle = workspace.Particles.PastParticles.ParticleEmitter
frame.DreamRepresentation.Text = "Present"
-- Controls the switch between dream/real
function DreamTags()
local DreamItems = workspace:GetChildren()
for _, item in DreamItems do
if item:IsA("Part") then
if item:HasTag("Dream") or item:HasTag("Real") then
if item:HasTag("Dream") then
if item.Transparency == 1 then
dreaming = true
task.spawn(function()
CompleteImpass(item,true)
end)
elseif item.Transparency == 0 then
dreaming = false
task.spawn(function()
CompleteImpass(item,false)
end)
end
elseif item:HasTag("Real") then
if item.Transparency == 1 then
dreaming = false
task.spawn(function()
CompleteImpass(item,true)
end)
elseif item.Transparency == 0 then
dreaming = true
task.spawn(function()
CompleteImpass(item,false)
end)
end
end
end
elseif item:IsA("Model") then
local parts = item:GetChildren()
if item:HasTag("Dream") then
for _, ModelParts in parts do
if ModelParts:IsA("BasePart") then
if ModelParts.Transparency == 1 then
task.spawn(function()
CompleteImpass(ModelParts,true)
end)
elseif ModelParts.Transparency == 0 then
task.spawn(function()
CompleteImpass(ModelParts,false)
end)
end
end
end
elseif item:HasTag("Real") then
for _, ModelParts in parts do
if ModelParts:IsA("BasePart") then
if ModelParts.Transparency == 1 then
dreaming = false
task.spawn(function()
CompleteImpass(ModelParts,true)
end)
elseif ModelParts.Transparency == 0 then
dreaming = true
task.spawn(function()
CompleteImpass(ModelParts,false)
end)
end
end
end
end
end
end
end
function MusicParticleLight()
local TesterReal = game.Workspace.TheTesterREAL
local TesterDream = game.Workspace.TheTesterFAKE
if TesterReal.Transparency == 0 then
PastParticle.Enabled = false
PastParticle:Clear()
SongPast:Pause()
SongCicada:Pause()
SongPresent:Play()
LightingDestroyer()
LightingSender(PresentLighting, "Present")
elseif TesterReal.Transparency == 1 then
PastParticle.Enabled = true
SongPresent:Pause()
SongPast:Play()
SongCicada:Play()
LightingDestroyer()
LightingSender(PastLighting, "Past")
end
if TesterDream.Transparency == 0 then
PastParticle.Enabled = true
SongPresent:Pause()
SongPast:Play()
SongCicada:Play()
LightingDestroyer()
LightingSender(PastLighting, "Past")
elseif TesterDream.Transparency == 1 then
PastParticle.Enabled = false
PastParticle:Clear()
SongPast:Pause()
SongCicada:Pause()
SongPresent:Play()
LightingDestroyer()
LightingSender(PresentLighting, "Present")
end
end
-- Changes the transparency depending on query
function CompleteImpass(part, query)
if query == false then
for i = 1, 10 do
part.Transparency += 0.1
task.wait(0.03)
end
part.Transparency = 1
part.CanCollide = false
part.CanTouch = false
part.CastShadow = false
elseif query == true then
for i = 1, 10 do
part.Transparency -= 0.1
task.wait(0.03)
end
part.Transparency = 0
part.CanCollide = true
part.CanTouch = true
part.CastShadow = true
end
end
-- Switches the Lighting Between Dream/Reality
function LightingSender(folder, times)
for _, v in folder:GetChildren() do
local copy = v:Clone()
copy.Name = (times .. v.Name)
copy.Parent = game.Lighting
end
end
function LightingDestroyer()
for _,v in game.Lighting:GetChildren() do
v:Destroy()
end
end
-- Input controller
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.E then
if debounce == false then
debounce = true
MusicParticleLight()
DreamTags()
if dreaming == false then
frame.DreamRepresentation.Text = "Present"
elseif dreaming == true then
frame.DreamRepresentation.Text = "Past"
else
frame.DreamRepresentation.Text = "Unknown timezone."
end
task.wait(1)
debounce = false
end
end
end)
And now, The function in particular we will be looking at:
elseif item:IsA("Model") then
local parts = item:GetChildren()
if item:HasTag("Dream") then
for _, ModelParts in parts do
if ModelParts:IsA("BasePart") then
if ModelParts.Transparency == 1 then
task.spawn(function()
CompleteImpass(ModelParts,true)
end)
elseif ModelParts.Transparency == 0 then
task.spawn(function()
CompleteImpass(ModelParts,false)
end)
end
end
end
elseif item:HasTag("Real") then
for _, ModelParts in parts do
if ModelParts:IsA("BasePart") then
if ModelParts.Transparency == 1 then
dreaming = false
task.spawn(function()
CompleteImpass(ModelParts,true)
end)
elseif ModelParts.Transparency == 0 then
dreaming = true
task.spawn(function()
CompleteImpass(ModelParts,false)
end)
end
end
end
end
end
end
end
Solutions I’ve tried:
So far I’ve tried to make a whole other section for the root part, but it doesnt change anything, and it stays visible. (Although I couldve done something wrong.)
PS: Please dont comment on my optimization or the fact im probably not doing things the most optimal way
, im still learning.