How to make tween for a button that doesn't exist yet

im cloning a frame called “ShopItemFrame” from replicated storage and the button exists inside the frame, and im using a remote fuction for the button tween, i dont know how to script it so the tween works after the frame has been cloned in PlayerGui. I tried to apply the tween in PlayerGui directly as its going to be cloned their but i cant seem to get it to work… Any help is appreciated!

local PlayerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui")
local CategoryContent = PlayerGui.ShopInterface.Holder.Content.CategoryContents.Contents.Limited:WaitForChild("CategoryContent")

-- ShopItemFrame is being cloned from replicated Storage
local ShopItemFrame = CategoryContent:WaitForChild("ShopItemFrame")
local TextButton = ShopItemFrame.Button

TextButton.Activated:Connect(function()
	local originalSize = ShopItemFrame.Size
	local newSize = originalSize + UDim2.new(-0.05, 0, -0.05, 0)

	ShopItemFrame:TweenSize(newSize, Enum.EasingDirection.In, Enum.EasingStyle.Quad, 0.05, true)

	game.ReplicatedStorage.BuyTrail:FireServer(ShopItemFrame.Name)

	wait(0.1)

	ShopItemFrame:TweenSize(originalSize, Enum.EasingDirection.In, Enum.EasingStyle.Quad, 0.05, true)
end)

3 Likes

Make the tween after the button exists

3 Likes

How exactly? I’ve tried using WaitForChild or FindFirstChild and yet it doesn’t work

3 Likes

Can you please mark down the part of the script to where it doesn’t work?

3 Likes

I’m guessing it’s line 3 and line 4 as that’s what does not exist yet and the rest code works fine when I code it with buttons that already exist

2 Likes

i guess i don’t know how to solve it

4 Likes
local idk = thing:WaitForChild("name")
local tweenname = tween:Create(idk, the rest of the arguements here)
tweenname:Play()
3 Likes

You could pre-make this and just not show it until it is to be used. Then it would just be a matter of updating the frame size and showing the button. As in, the button was always there.

2 Likes

Where is this script? ???

2 Likes

Use “task.spawn” to spawn a new function, then set it to wait until the item loads before creating the tween.

(This can be accomplished in different ways.)

Are there any UI constraints in the frame or button which might interfere with the resizing?

Is the Active property set to true?

Does the button.activated:Connect work? (Will it print something when clicked?)

If you add a print after defining ShopItemFrame does it print?

Does the clone script definitely clone the ShopItemFrame to the correct player’s Gui? (And not startergui or something)

1 Like