(Solved) Issue with TweenService

For some reason, I loaded in today and I was going crazy because my script won’t function right. I was trying to make a main menu and there was a problem with the script I checked back multiple times and the output said nothing. There should not be anything wrong, The script is basically just opening a frame with Tweenservice by clicking a Textbutton and printing some stuff. Also there was just a line or two of code that made the previous frames visible / invisible.

script

local button = script.Parent
local newframe = script.Parent.Parent.Parent.newframe1

function changeframe()
	
	newframe.Visible = true
	if newframe.Visible == true then
		print("Button Clicked, Recieving TweenService")
		wait(0.8)
		print("Successfully Recieved TweenService, Tweenscript1")
		
	end

	local tweenService = game:GetService("TweenService")
	
	local info = TweenInfo.new(
	0.8,-- duration
	Enum.EasingStyle.Quad, -- easing style
	Enum.EasingDirection.Out, -- easing direction
	0, -- number of times to repeat (0 means no loop)
	false, -- reverses the animation if true
	0.0) -- delay before starting
	
	local goal = {
		
		Size = UDim2.new(1.5, 0 , 1.5 , 0),
		
		
		
		
		
	}
	
	local tween = tweenService:Create(newframe, info , goal)
	tween:Play()
	
	button.Visible = false
	
end

button.MouseButton1Click:Connect(changeframe) -- when the button is clicked, run the function newgui

someone pls help

[quote=“meow, post:1, topic:2506976, full:true, username:drxvned”]
For some reason, I loaded in today and I was going crazy because my script won’t function right. I was trying to make a main menu and there was a problem with the script I checked back multiple times and the output said nothing. There should not be anything wrong, The script is basically just opening a frame with Tweenservice by clicking a Textbutton and printing some stuff. Also there was just a line or two of code that made the previous frames visible / invisible.

script

local button = script.Parent
local newframe = script.Parent.Parent.Parent.newframe1

function changeframe()
	
	newframe.Visible = true
	if newframe.Visible == true then
		print("Button Clicked, Recieving TweenService")
		wait(0.8)
		print("Successfully Recieved TweenService, Tweenscript1")
		
	end

	local tweenService = game:GetService("TweenService")
	
	local info = TweenInfo.new(
	0.8,-- duration
	Enum.EasingStyle.Quad, -- easing style
	Enum.EasingDirection.Out, -- easing direction
	0, -- number of times to repeat (0 means no loop)
	false, -- reverses the animation if true
	0.0) -- delay before starting
	
	local goal = {
		
		Size = UDim2.new(1.5, 0 , 1.5 , 0),
		
		
		
		
		
	}
	
	local tween = tweenService:Create(newframe, info , goal)
	tween:Play()
	
	button.Visible = false
	
end

button.MouseButton1Click:Connect(changeframe) -- when the button is clicked, run the function newgui

someone pls help

EDIT: The issue was that I had an invalid variable. I had an image background for my menu but I was having issues so I deleted it and I had it as a variable. Because there was this error, the script did not run and for some reason there was no red marks in the script or in the output

2 Likes

No idea what your code is doing at the start but I’ll just give it a quick rewrite for you, with comments to explain. Apologies if I make any unwanted changes.

local button = script.Parent
local newframe = script.Parent.Parent.Parent.newframe1
local tweenService = game:GetService("TweenService") -- Always use GetService() for variables up here

local info = TweenInfo.new(
	0.8,-- duration
	Enum.EasingStyle.Quad, -- easing style
	Enum.EasingDirection.Out, -- easing direction
)
-- Last 3 parameters are default to 0, false, and 0

local goal = {
		Size = UDim2.new(1.5, 0 , 1.5 , 0),
}
-- Keep constant variables (ones that don't change) outside of loops or functions to reduce processing power waste


function changeframe()
	newframe.Visible = true
	print("Button clicked, tweening")

	local tween = tweenService:Create(newframe, info , goal)
	tween:Play()
	
	tween.Completed:Wait() -- Wait for the tween to finish
	print("Successfully tweened, Tweenscript1")
	
	button.Visible = false
	tween:Destroy() -- Destroy the tween to prevent memory leaks
	-- (in this case you created a new tween but never destroyed them)
end

button.MouseButton1Click:Connect(changeframe) -- when the button is clicked, run the function newgui