Why is this happening? (SurfaceGui Script)

Hi, I’m trying to create a script that repeats something everytime a button is clicked on.

As you can see in the video, the script works perfectly the fine the first time it’s ran. However, the second time, the ‘Functions’ frame doesn’t get tweened. Why is this happening and how can I fix it?


Script:

local Logo = script.Parent.Parent.Parent.Parent.Screen.SurfaceGui.Frame.Logo
local LogoFrame = script.Parent.Parent.Parent.Parent.Screen.SurfaceGui.Frame
local Functions = script.Parent.Parent.Parent.Parent.Screen.SurfaceGui.Functions

script.Parent.MouseButton1Click:Connect(function()
	wait(0.5)
	script.Parent.Visible = false
	wait(0.5)
	Logo.ImageTransparency = 0.1
	wait(0.01)
	Logo.ImageTransparency = 0.3
	wait(0.01)
	Logo.ImageTransparency = 0.7
	wait(0.01)
	Logo.ImageTransparency = 0.9
	wait(0.01)
	Logo.ImageTransparency = 1
	LogoFrame.Visible = false
	wait(1)
	Functions:TweenPosition(UDim2.new(0, 0, 0, 0),"Out","Quart",0.5)
	
end)

Workspace:

image

I’ve made a reply about this once before. I will send you the discussion.

My script is not a LocalScript, it’s a server script. My problem is also not the same. The first time the script is ran, it works fine. Any more times, everything works except the frame tweening.

Did you check the Visible property of the Functions UI when it is tweened?

Oh, sorry I misunderstood.

You need to make sure you reset the positions and properties of the UI after it is done.

Yes, the Functions frame remains visible.

One suggestion on a way to do this is by making a clone of the SurfaceGui before starting the animations, then deleting the SurfaceGui and replacing it with the clone once the animation is over.

This is unrelated, but don’t use wait(0.01) if you’re wanting the Image to disappear for a certain amount of time, either use RunService.Stepped or Tween it using TweenService

It doesn’t look like you’re changing back the properties of the ImageTransparency & Visible back to their original states (At least provided inside the script you gave us), you could try printing what their properties are supposed to be?

It seems like you only provided us the script when the frame enters. Can you provide us with the script when you exit? There could be something when you exit the frame.

@JackscarIitt @Quwanterz

Exit Script

local Logo = game.Workspace.Screener1.Screen.SurfaceGui.Frame.Logo
local LogoFrame = game.Workspace.Screener1.Screen.SurfaceGui.Frame
local Functions = game.Workspace.Screener1.Screen.SurfaceGui.Functions

script.Parent.Activated:Connect(function()
	Functions:TweenPosition(UDim2.new(0, -150, 0, 0),"Out","Quart",0.5)
	wait(1)
	LogoFrame.Visible = true
		Logo.ImageTransparency = 0.9
		wait(0.01)
		Logo.ImageTransparency = 0.7
		wait(0.01)
		Logo.ImageTransparency = 0.3
		wait(0.01)
		Logo.ImageTransparency = 0.1
		wait(0.01)
		Logo.ImageTransparency = 0
end)

Exit Workspace: (in a ScreenGui)
image

Hopefully something here helps. A video is uploading.

I can’t seem to find any problem with the script.

My theory is that:

  1. Another visible UI is overlapping the Functions frame, thus not showing it.
  2. The Functions frame remains not visible.

While playing the game, check each of the UI’s property to see any unusual values.

There is nothing overlapping, the issue is that the frame doesn’t tween at all.

Hmm…

Try passing another argument to the TweenPosition function and setting it to true.

Yeah, I have noticed that on the second you clicked, the Position property of the Functions frame didn’t change. It seems like the method TweenPosition didn’t register at all.

The problem might be you have too many wait. I would suggest tweening the ImageTransparency using TweenService.

Although I do suggest using TweenService for the ImageTransparency, I don’t think the use of wait is the issue. Because it works the first time.

Sorry, what changes should I make and where should I make them exactly? Not sure what much of this means, I have very little experience with programming.

It’s not because of the wait, I tried getting rid of the waits and the issue still stands.

This becomes:

Functions:TweenPosition(UDim2.new(0, 0, 0, 0),"Out","Quart",0.5,true)

This becomes:

Functions:TweenPosition(UDim2.new(0, -150, 0, 0),"Out","Quart",0.5,true)

Still doesn’t work, the frame position still doesn’t change.

On the main script, for experimental purposes, try getting rid of the tween and just setting the position. I want to see if that works.