TweenPosition not working?

I am trying to tween a frame like usual how I do in all my scripts while working with UI and its just not working, there are no errors or anything printing into the console.

local shopIcon = script.Parent.shopIcon
local shopButton = shopIcon.shopButton
local storeFrame = script.Parent.storeFrame
local storeToggle = storeFrame.storeToggle.Value

shopButton.MouseButton1Click:Connect(function()
	if storeToggle == false then
		storeFrame:TweenPosition(UDim2.new(0.207, 0,0.223, 0))
		wait(2)
		storeToggle = true
	elseif storeToggle == true then
		storeFrame:TweenPosition(UDim2.new(0.207, 0,1.1, 0))
		wait(2)
		storeToggle = false
	end
end)

The script above isn’t working, but yet when I join the game and run a command shown below it works perfectly fine…

game.Players.LocalPlayer.PlayerGui.Main.storeFrame:TweenPosition(UDim2.new(0.207, 0,0.223, 0))

Any clue at all what is going on or is there just an error going on inside of Roblox Studio ?

Did you set the variable “storeToggle” to false correctly?

image

TweenPosition uses more than just UDim2, you would need to add more Arguments to it for it to function, for Example:

storeFrame:TweenPosition(
    UDim2.fromScale(.207,.223),
    "InOut", -- EasingDirection
    "Linear", -- EasingStyle
    1 -- Duration
    -- there are 3 more Aguments
)

Tried this already before, didn’t work

shopButton.MouseButton1Click:Connect(function()
	if not storeToggle then
		storeFrame:TweenPosition(UDim2.new(0.207, 0,0.223, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Linear, 1, nil, nil)
		wait(2)
		storeToggle = true
	elseif storeToggle then
		storeFrame:TweenPosition(UDim2.new(0.207, 0,1.1, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Linear, 1, nil, nil)
		wait(2)
		storeToggle = false
	end
end)

^ also this isnt true

1 Like

forgot about argument or Default

function prints(x: number)
    print(x or 1) -- if x is nil, it will print 1
end

prints(2) --> 2
prints() --> 1
prints(nil) --> 1

Just asking, have you actually checked if these Exist? Use WaitForChild() if you’re using the Client, Not everything will load right away.

I am sure these exist, I even re wrote the whole script just incase

image

THats not what I’m saying, If you read what I said:

I did use WaitForChild() and it didnt work

I would go with what xGOA7x said, and use: UDim2.fromScale, for example:

TS = game:GetService("TweenService")

local shopIcon = script.Parent.shopIcon
local shopButton = shopIcon.shopButton
local storeFrame = script.Parent.storeFrame
local storeToggle = storeFrame.storeToggle.Value

local tweenDuration = 1
local TweenInfo = TweenInfo.new(tweenDuration, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0)
local TweenPropsIn = {Position = UDim2.fromScale(0.207, 0.223)}
local TweenPropsOut = {Position = UDim2.fromScale(0.207, 1.1)}
local FrameTweenIn = TS:Create(storeFrame, TweenInfo, TweenPropsIn)
local FrameTweenOut = TS:Create(storeFrame, TweenInfo, TweenPropsOut)

shopButton.MouseButton1Click:Connect(function()
	if storeToggle == false then
        print("storeToggle = false") -- See if this prints
		FrameTweenIn:Play()
		wait(2)
		storeToggle = true
    end
	if storeToggle == true then
        print("storeToggle = true") -- See if this prints
		FrameTweenOut:Play()
		wait(2)
		storeToggle = false
	end
end)

Hopefully this fixes the issue!

Add ,"Out","Quad",1.4 so it can work.

I recommend using task.wait instead of wait.

local shopIcon = script.Parent.shopIcon
local shopButton = shopIcon.shopButton
local storeFrame = script.Parent.storeFrame
local storeToggle = storeFrame.storeToggle

shopButton.MouseButton1Click:Connect(function()
	if storeToggle.Value == false then
		storeFrame:TweenPosition(UDim2.new(0.207, 0,0.223, 0),"Out","Quad",1.4)
		task.wait(2)
		storeToggle.Value = true
	elseif storeToggle.Value == true then
		storeFrame:TweenPosition(UDim2.new(0.207, 0,1.1, 0),"Out","Quad",1.4)
		task.wait(2)
		storeToggle.Value = false
	end
end)