Currently, I am trying to to create a module function where a part disappears and reappears. Whenever transparency is 1, CanCollide is false, and whenever transparency is 0, CanCollide is true. I’m using the Roblox tween service to change the part transparency.
Right now, the script is causing too much lag due to the GetPropertyChangedSignal function, but I am unsure of any other way to create a script that will preform the actions above. Can anyone help me out or guide me in the right direction?
for k, shadowpart in pairs(shadowpartFolder:GetChildren()) do
local goal = {}
goal.Transparency = 1
local goal2 = {}
goal2.Transparency = 0
local goal3 = {}
goal3.Transparency = 1
goal3.CFrame = shadowpart.CFrame + Vector3.new(0,0,25)
local tweenInfo = TweenInfo.new(3, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, -1, true, 1)
local tween = TweenService:Create(shadowpart, tweenInfo, goal)
local tween2 = TweenService:Create(shadowpart.Union, tweenInfo, goal)
local tween3 = TweenService:Create(shadowpart, tweenInfo, goal2)
local tween4 = TweenService:Create(shadowpart.Union, tweenInfo, goal2)
local tween5 = TweenService:Create(shadowpart, tweenInfo, goal3)
local tween6 = TweenService:Create(shadowpart.Union, tweenInfo, goal3)
if shadowpart.Name == "1" then
tween:Play()
tween2:Play()
elseif shadowpart.Name == "2" then
tween3:Play()
tween4:Play()
elseif shadowpart.Name == "3" then
tween5:Play()
tween6:Play()
end
local union = shadowpart.Union
shadowpart:GetPropertyChangedSignal("Transparency"):Connect(function()
if shadowpart.Transparency <= 1 and shadowpart.Transparency > 0.75 then
shadowpart.CanCollide = false
union.CanCollide = false
elseif shadowpart.Transparency <= 0.75 then
shadowpart.CanCollide = true
union.CanCollide = true
end
end)
end