Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why is this frame not tweening correctly?

When I click the playbutton the tween works but then when I click the back button it does not tween smoothly to its original position and when I click the playbutton again, it doesn't tween like it did the first time. I am so confused.

local backgroundframe = script.Parent
local campaignbackground = backgroundframe.CampaignBackground
local back = campaignbackground.Back

playbutton.MouseButton1Down:connect(function()
	campaignbackground.Visible = true
	campaignbackground:TweenPosition(UDim2.new(0, 0, 0, 0), "Out", "Quad", 1, true)
end)
	
back.MouseButton1Down:connect(function()
	campaignbackground:TweenPosition(UDim2.new(-0.25, 0, -200, 0), "Out", "Quad", 1, true)
	campaignbackground.Visible = false
end)

1 comment

0

For your back button, you need to wait for the tween to complete before you make it invisible.

3 answers

Your script is very very very confuse.... I prefer to use a Script inside the button..

Try use this:

First - Create a Script inside the button Second - Use this code and modify:

ButtonName:TweenPosition(UDim2.new(0,0,0,0),"In","Quad",0.5)

Tweening does not yield the script. You are turning the frame invisible right after telling it to tween. It does tween, but is not visible. add a wait() to delay before making the frame invisible.

That's not how it works.

Here, let me help you:

repeat wait() until game.Players.LocalPlayer:WaitForChild("PlayerGui")

local Bf = script.Parent --I used Bf to make the variable be short
local Cb = Bf.CampaignBackground --Once more, I used Cb to make the variable be short, because jeez
local back = Cb.Back
--I added the playbutton variable, because you didn't specify it. Please replace the test path with the correct one.
local playbutton = game.Players.LocalPlayer.PlayerGui.TestGui.TestFrame.TestTextButton
--Add a variable that controls the Tweening.
local isActivated = false

playbutton.MouseButton1Down:connect(function()
	if isActivated = false then
		isActivated = true
	    	Cb.Visible = true
	    	Cb:TweenPosition(UDim2.new(0, 0, 0, 0), "Out", "Quad", 1, true)
	end
end)

back.MouseButton1Down:connect(function()
	if isActivated = true then
		isActivated = false
	    	Cb:TweenPosition(UDim2.new(-0.25, 0, -200, 0), "Out", "Quad", 1, true)
	    	Cb.Visible = false
	end
end)

If it works, let me know, and please mark this answer as the solution. If this doesn't work, leave a comment saying why, and I'll edit and try to make it work.

As always, good scripting! ;D

This discussion is preserved as it was. New answers, comments, and votes are closed.