Tween not working properly

This is a script where I’m trying to tween a button from transparency 1 to 0, and the position at the same time such that it fades in.

local Players = game:GetService("Players")
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local TweenService = game:GetService("TweenService")

local plr = Players.LocalPlayer
local gui = script:FindFirstChild("LobbyLoadingUI")
local plrGui = plr:WaitForChild("PlayerGui")
local Main = script.LobbyLoadingUI.Main

local Bar = Main.Holder.Bar 
local Assets = Main.Holder.AssetsLoaded
local skip = Main.Skip

local tweenSkip = TweenInfo.new(1.5,Enum.EasingStyle.Linear,Enum.EasingDirection.In)
local tweenTrans = TweenInfo.new(1.5,Enum.EasingStyle.Linear)
local tweenrotate = TweenInfo.new(1.2,Enum.EasingStyle.Circular,Enum.EasingDirection.In,-1,true)
local UIGrad = skip.UIStroke.UIGradient

local TweenSkipBtn = TweenService:Create(skip, tweenSkip, {Position = UDim2.new(0.5,0,0.75,0)})
local TweenSkipTextTrans = TweenService:Create(skip, tweenTrans, {TextTransparency = 0})
local TweenSkipBtnBgTrans = TweenService:Create(skip, tweenTrans, {BackgroundTransparency = 0})
local TweenSkipUiStroke = TweenService:Create(skip, tweenTrans, {Transparency = 0})
local TweenRotateGrad = TweenService:Create(UIGrad, tweenrotate, {Rotation = 360})

gui.Parent = plrGui

ReplicatedFirst:RemoveDefaultLoadingScreen()

local loaded = game:IsLoaded()
local timeLoaded = 0

repeat timeLoaded += task.wait() 
	
until loaded or timeLoaded >=6

if loaded or timeLoaded >=6 then

	skip:TweenPosition(UDim2.new(0.5,0,0.75,0), Enum.EasingDirection.InOut,Enum.EasingStyle.Linear,1.5)
	TweenSkipTextTrans:Play()
	TweenSkipBtnBgTrans:Play()

	task.wait(3)

	UIGrad.Enabled = true
	
	if UIGrad.Enabled == true then
		TweenRotateGrad:Play()
	end
end

The issue here is that the skip button (for the loading) doesn’t even fade in and appear as transparency = 0 the moment the gui replicates to PlayerGui. I am not sure if the tween has already played, but it wouldn’t make sense since I have a yield of 6 seconds before it plays, unless what I am doing is wrong. If so I hope somebody could help correct this part of my code, thank you.

*original position of the button is (0.5,0,0.9,0)

Additional detail: The studio AI Assistant seems to suggest me to use runservice event? (I don’t see any part of the script that has the runservice as well?) and this is the code that it gives:

-- Script for playing tween when game has not yet loaded

local gui = script.Parent

local loaded = false

-- Function to play the tween
local function playTween()
    gui:TweenPosition(UDim2.new(0, 0, 0, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quad, 1, true)
end

-- Check if the game is loaded
local function checkLoaded()
    if not loaded and game:IsLoaded() then
        loaded = true
        playTween()
    end
end

-- Connect the checkLoaded function to the game load event
game.Loaded:Connect(checkLoaded)

-- Call the checkLoaded function once in case the game is already loaded
checkLoaded()

I have no idea if the Ai knows what I’m trying to do as this part of the code;

local function checkLoaded()
if not loaded and game:IsLoaded() then
loaded = true
playTween()

seems that the tween only plays when game:IsLoaded() which is not what I want, since it is a button that removes the loading screen where the loading is based on #Descendents in the entire game, essentially the entire game to be loaded. Well Unless I misunderstood this statement of course.

2 Likes

Ignore this post…It doesn’t work from testing in studio but it does in-game on roblox website…Just gonna put the post out here for anyone who wants to copy for whatever reason.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.