Hi Devs,
Hope all is well. I’m currently working on Tweening UI and… well, I wouldn’t say it’s the most stable. Let me show you what I mean:
If a person enters and leaves the left side of the screen too quickly then it will break. Sometimes even randomly. I’m not sure what to do. Here’s the script as of now. What do I do? I’ve tried using debounce, didn’t work out very well, maybe I didn’t do it properly…
local CollectionService = game:GetService("CollectionService")
local TweenService = game:GetService("TweenService")
local debounce = false
local ViewportCamera = Instance.new("Camera") ViewportCamera.Name = "VFCamera" ViewportCamera.Parent = script.Parent.Background.Episodes.Map
-- Sea Animation
local RepeatTweenInfo = TweenInfo.new(10, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, -1, true)
local WaveTween = TweenService:Create(script.Parent.Background.Episodes.Map.WorldModel.background.Texture, RepeatTweenInfo, {OffsetStudsU = 5,OffsetStudsV = -5})
WaveTween:Play()
for _, Season in pairs(CollectionService:GetTagged("Season")) do
-- Variables
local Background = Season.Parent.Parent.Parent.Parent.Parent
local CurrentSeason = Background:GetAttribute("CurrentSeason")
local MapContents = Background.Episodes.MapContents
local MapViewport = Background.Episodes.Map
MapViewport.CurrentCamera = ViewportCamera -- Sets "VFCamera" as the Map Viewport's CurrentCamera
local SemiTransEpisodeFrame = {}
SemiTransEpisodeFrame.GroupTransparency = 0.5
SemiTransEpisodeFrame.Position = UDim2.new(0.29, 0,0.07, 0)
SemiTransEpisodeFrame.Size = UDim2.new(0.654, 0,0.876, 0)
local OpaqueEpisodeFrame = {}
OpaqueEpisodeFrame.GroupTransparency = 0
OpaqueEpisodeFrame.Position = UDim2.new(0.266, 0,0.02, 0)
OpaqueEpisodeFrame.Size = UDim2.new(0.723, 0,0.959, 0)
local BigSeasonFrame = {}
BigSeasonFrame.Size = UDim2.new(0.306, 0,0.959, 0)
BigSeasonFrame.Position = UDim2.new(0.01, 0,0.02, 0)
local SmallSeasonFrame = {}
SmallSeasonFrame.Size = UDim2.new(0.246, 0,0.959, 0)
SmallSeasonFrame.Position = UDim2.new(0.01, 0,0.02, 0)
local OpaqueEP = TweenService:Create(Background.Episodes, TweenInfo.new(0.3, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut), OpaqueEpisodeFrame)
local SemiTransparentEP = TweenService:Create(Background.Episodes, TweenInfo.new(0.3, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut), SemiTransEpisodeFrame)
local BigSeason = TweenService:Create(Background.Seasons, TweenInfo.new(0.3, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut), BigSeasonFrame)
local SmallSeason = TweenService:Create(Background.Seasons, TweenInfo.new(0.3, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut), SmallSeasonFrame)
Background.Seasons.MouseEnter:Connect(function() -- Season Button on hover
--if debounce == false then
-- debounce = true
OpaqueEP:Cancel()
SemiTransparentEP:Play()
BigSeason:Play()
Background.Parent.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
-- debounce = false
--end
end)
Background.Seasons.MouseLeave:Connect(function() -- Season Button on normal
SemiTransparentEP:Cancel()
OpaqueEP:Play()
SmallSeason:Play()
OpaqueEP.Completed:Wait()
Background.Parent.ZIndexBehavior = Enum.ZIndexBehavior.Global
end)
Season.MouseButton1Down:Connect(function() -- Season Button on press
-- Tween Goals
local BackgroundColor = {}
BackgroundColor.BackgroundColor3 = Season:GetAttribute("BackgroundColor")
local ButtonColor = {}
ButtonColor.BackgroundColor3 = Season:GetAttribute("ButtonColor")
local ContentColor = {}
ContentColor.BackgroundColor3 = Season:GetAttribute("ContentColor")
local SeaColor = {}
SeaColor.Color = Season:GetAttribute("SeaColor")
local SecondaryColor = {}
SecondaryColor.BackgroundColor3 = Season:GetAttribute("SecondaryColor")
local CFramePosition = {}
CFramePosition.CFrame = Season:GetAttribute("CFrame")
--Tween Information
local TweenInfoMap = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut)
local TweenInfoUI = TweenInfo.new(0.5, Enum.EasingStyle.Circular, Enum.EasingDirection.InOut)
--Tween Declaration
local BackgroundTween = TweenService:Create(Background, TweenInfoUI, BackgroundColor)
local CornerTween = TweenService:Create(Background.Episodes.Corner, TweenInfoUI, BackgroundColor)
local BackButtonTween = TweenService:Create(Background.Episodes.Corner.Back, TweenInfoUI, ButtonColor)
local SideButtonTween = TweenService:Create(Background.SideButton, TweenInfoUI, ButtonColor)
local SideWindowTween = TweenService:Create(Background.Seasons, TweenInfoUI, SecondaryColor)
local SeaTween = TweenService:Create(MapViewport.WorldModel.background, TweenInfoUI, SeaColor)
local MapPosition = TweenService:Create(MapViewport.VFCamera, TweenInfoMap, CFramePosition)
local InitialSeason = MapViewport:GetAttribute("Season")
local SeasonName = Season:GetAttribute("SeasonName")
print(SeasonName)
print("Button pressed")
local function PlayTweens() -- Plays all tweens at once when called
BackgroundTween:Play()
BackButtonTween:Play()
SideButtonTween:Play()
SideWindowTween:Play()
CornerTween:Play()
MapPosition:Play()
SeaTween:Play()
MapPosition.Completed:Wait()
end
if InitialSeason ~= SeasonName and InitialSeason ~= "" and InitialSeason ~= nil then
print("The Initial Season was: " .. InitialSeason)
MapContents:FindFirstChild(InitialSeason).Frame.Visible = false
elseif InitialSeason == "" or InitialSeason == nil then
print("InitialSeason is empty")
end
local Map = MapContents:FindFirstChild(SeasonName)
MapViewport:SetAttribute("Season", Map.Name)
print("Map chosen: " .. Map.Name)
PlayTweens() -- Calls function to play all tweens
Map.Frame.Visible = true
for _, Episode in pairs(Map.Frame:GetChildren()) do
--unfinished
end
end)
end
Thanks!
Aki