Tween not working

Im trying to make a button that slides to turn sfx off heres the problem when I click the button the tween won’t play idk why that is act like the function tweening doesnt exist bc I always used that 1 but I only know hot to manupilate the place with that not more like a color my output does print 1 and 3 btw

local TS = game:GetService("TweenService")
local SS = game:GetService("SoundService")
local SFX = SS.SFX:GetChildren()
local Button = script.Parent
local Value = script.Value
local BOn = script.Parent.Parent.ButtonOn
local BOf = script.Parent.Parent.ButtonOff
local Operator = false
local ButtonM = script.Parent.Parent.Button

local info = TweenInfo.new(
	1,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.Out,
	0.2,
	false
)


local tween = TS:Create(Button, info, {Position = BOf.Position, BackgroundColor3 = BOf.BackgroundColor3})






local function Tweening(button, location)
	button:TweenPosition(UDim2.new(location), --position
		Enum.EasingDirection.Out, --Direction
		Enum.EasingStyle.Linear, --Style
		0.2, --Time
		false) --again?
end


Button.MouseButton1Up:Connect(function()
	print("1")
	if Operator == true then
		print("2")
		print("in sessoion")
	elseif Operator == false then
		print("3")
		SFX.Volume = 0
		tween:Play()
		wait(0.2)
		print("clicked")
		
	end
end)
1 Like

According to Roblox Docs on TweenInfo

-- A TweenInfo that repeats itself 4 times.

TweenInfo.new(0.5, Enum.EasingStyle.Back, Enum.EasingDirection.In, 4)

Your tween should repeat 0.2 times which makes no sense at all. Do you meant swap with that 1 ?

New TweenInfo:

local info = TweenInfo.new(
	0.2,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.Out,
	1
)
1 Like

As snapnat said, you should swap 1 and 0.2, or just simply put 1 instead of 0.2, so the slide will be 1 second and will repeat 1 time

well I swapped the 2 of them but I got the exact same problem as before the buttons doesnt do anything and the code still runs you were right abt that litlle mistake I made. I made it out of habit too bad it didnt solve the problem

local function Tweening(button, location)
button:TweenPosition(UDim2.new(location), --position
Enum.EasingDirection.Out, --Direction
Enum.EasingStyle.Linear, --Style
0.2, --Time
false) --again?
end

I usually use that form of the tween

1 Like

Can you try adding a breakpoint before tween and observe what’s happening as you step through?

I alr did

Button.MouseButton1Up:Connect(function()
	print("1")
	if Operator == true then
		print("2")
		print("in sessoion")
	elseif Operator == false then
		print("3")
		SFX.Volume = 0
		tween:Play()
		wait(0.2)
		print("clicked")
		
	end
end)

but it prints 3 and clicked so the problem has to be in the tween itself and I dont know why it doesnt work since I never worked with this version of the tweens

1 Like

Oohh, lol.

It seems like you dont really use your TweenInfo and TweenService :moyai:
It seems like that me and snapnat were talking about TweenInfo that you dont use.

1 Like

And I’m wrong again you really use your TweenInfo bruhh. Sorry for inconvenience

1 Like

You dont set your operator to true or false? Maybe thats the problem?

If not, before the end) I recommend you to put this line of code:

Operator = not Operator

It basically sets Operator to opposite version of itself (if Operator = true, then Operator = false)

1 Like

Yea but heres the thign I havnt add anythign to that function that would change the operator I alr set the boolvalue of the operator to false thats why it does print “3” and “clicked” I know the problem isnt in the function but it has to be in the tween itself somewhere only I dont know what

1 Like

I alr added breakpoints to see or it works but it doesnt give me errors but it does print the breakpoints i set

1 Like

I can also call the tween iutself without needing to be pressed by tween:Play()
but still the same result nothing happens

Hmm…
I dont really know whats happening there lol :slightly_frowning_face:

1 Like

ah okay np thx for trying to help I have no idea myself tbh since it all looks clean and no errors so yea I hiope someone know the issue

1 Like

Wait, could you repeat the situation again? Dont really understand the description.

1 Like

Sorry I was online searching for a solution. uhm lets see Im making a button that can slide on and off wiht changing color I set to change these 2 properties of the frame so it makes a nice sliding effect. Only it seems like the tween doesnt run I also tried changing the lcoation to somewhere else and color to a total differenct color nothing happens. I also added multiple breakingpoint in the mousebutton1up function but they all printed. and following to my output the print says it played but there wasnt any movement or clor change

I also asked chat GPT but he didnt find any weird thigns so I really dk what to do

If anything, it could be a problem with your UI or the way you declared them as variables. You could have mixed it up in some way by accident. I recommend that you go through your UI tree and see if you actually got the right UI Object in the first place, make sure you’re tweening the right button etc etc. It could be your button’s visible property is set to false, or it’s position is already at your designated position based on where it was placed. So if you don’t mind, show us your UI hierarchy in StarterGui or wherever you keep it, this might give a better indication as to what the problem actually is. ALSO ALSO, do make sure the UI Objects transparency is at 0, otherwise you will not see any color change. I tried using your script with my own UI and it works perfectly fine. Fiddle around with your stuff there and I’m sure you’ll find a solution. As Timati4Life mentioned, make sure you make an “on” version of the tween otherwise it’ll continuously keep it off :sweat_smile:

2 Likes

Is it already off? Because you set only 1 tween with ButtonOff properties

2 Likes

uhm alr heres the thing im dumb ash and you were right I checked or I was changing the button value only I tot forgat I was using a frame for the vision and an transparent imagebutton as button so thats why I didnt see any changes tysm cant believe such a small dumb mistake can cost so much time

Everyone tysm for the help!! :muscle:

3 Likes