I’m making a function to toggle a loading screen on and off with a transition. I set up a couple of tweens that i then tried to reuse for both the “On” and “Off” animation. The problem is that once a tween has finished the .Completed
event runs for both cases is when things start to break. I’ve tried to look for something like this on the DevForum but with no results. so I’m writing a post here.
Here’s generally how the function looks like.
-- Tween1 and Tween2 are defined before the function
local function ToggleLoadingScreen(bool)
Tween1:Play()
Tween1.Completed:Connect(function()
GUI.Visible = bool
Tween2:Play()
end)
end
ReplicatedStorage.MapLoading.Changed:Connect(function(bool)
ToggleLoadingScreen(bool)
end)
I tried printing the bool value when Tween1 completed, which returned the correct value the first time the function ran but then started going back and forth between true
and false
with every next value change.