Hello, I have been trying to make a script in which once the tween service has been completed, the brick will turn invisible until the tween service is played again. However, once the tween is completed, it doesn’t turn invisible.
local TweenService = game:GetService("TweenService")
local part = script.Parent
local targetBrick = game.Workspace.TargetBrick
local tweenInfo = TweenInfo.new(
15,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out,
-1,
false,
5
)
local tween = TweenService:Create(part,tweenInfo,{Position = targetBrick.Position})
tween.Completed:Connect(function(playbackState)
if playbackState == Enum.PlaybackState.Completed then
print("COmpleted!")
part.Transparency = 1
end
end)
tween:Play()
while true do
wait()
if(part.Position == targetBrick.Position) then
part.Transparency = 1
else
part.Transparency = 0
end
end
I tested the code in my own studio and found that the issue was within your TweenInfo.
If you would like to add delay time, then you should consider task.wait(number_of_seconds).
Fixed code:
local TweenService = game:GetService("TweenService");
local part = script.Parent
local targetBrick = game.Workspace.TargetBrick
local tweenInfo = TweenInfo.new(
15,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out
);
local tween = TweenService:Create(part,tweenInfo,{Position = targetBrick.Position})
tween.Completed:Connect(function(playbackState)
if playbackState == Enum.PlaybackState.Completed then
print("COmpleted!")
part.Transparency = 1
end
end)
task.wait(5); -- this is your delay time
tween:Play()
Basically, I want the tween to fire first, and once completed the brick goes to transparent and waits a certain amount of time before becoming visible again and the loop playing again.
You can achieve this by saving state values of your original properties!
Desired code:
local TweenService = game:GetService("TweenService");
local part = script.Parent
local targetBrick = game.Workspace.TargetBrick
local originalPos = part.Position
local tweenInfo = TweenInfo.new(
15,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out
);
local tween = TweenService:Create(part,tweenInfo,{Position = targetBrick.Position});
while task.wait(5) do
part.Position = originalPos
part.Transparency
tween:Play();
tween.Completed:Wait();
part.Transparency = 1
end
local TweenService = game:GetService("TweenService");
local part = script.Parent
local targetBrick = game.Workspace.TargetBrick
local tweenInfo = TweenInfo.new(1,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,5);
while true do
local tween = TweenService:Create(part,tweenInfo,{Position = targetBrick.Position})
tween:Play()
tween.Completed:Wait()
part.Transparency = 1
task.wait(5)
part.Transparency = 0
end