Ui instances won't scale

i have a custom prompt and i want the udim2 size to be all 0 by default and scale up when the prompt is shown but when the prompt show, it just wont scale up idk what im doing wrong. i appreciate any help ty

local sizeOfUI = {}

local function getUISize()

	--store ui instance size in table
	for _, ui_Instance in ipairs(PP_UI:GetDescendants()) do
		if ui_Instance:IsA("Frame") or ui_Instance:IsA("TextLabel") then
			sizeOfUI[ui_Instance.Name] = ui_Instance.Size
		end
	end

	return sizeOfUI
end

local function HideUI()
	-- Reset the sizes to 0 before scaling them up
	for _, ui_Instance in ipairs(PP_UI:GetDescendants()) do
		if ui_Instance:IsA("Frame") or ui_Instance:IsA("TextLabel") then
			ui_Instance.Size = UDim2.new(0, 0, 0, 0)  -- Reset to a small size
		end
	end
end

HideUI()

local function showPrompt()
	local sizeofUI = getUISize()

	local tweenInfo = TweenInfo.new(1.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, false, 0)

	for _, ui_Instance in ipairs(PP_UI:GetDescendants()) do
		if ui_Instance:IsA("Frame") or ui_Instance:IsA("TextLabel") then
			for key, size in pairs(sizeofUI) do
				if ui_Instance.Name == key then
					local tween = ts:Create(ui_Instance, tweenInfo, {Size = size})
					tween:Play()
				end
			end
		end
	end
end

pp.PromptShown:Connect(showPrompt)

local function hidePrompt()
	local tweenInfo = TweenInfo.new(1.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, false, 0)

	for _, ui_Instance in ipairs(PP_UI:GetDescendants()) do
		if ui_Instance:IsA("Frame") or ui_Instance:IsA("TextLabel") then
			local tween = ts:Create(ui_Instance, tweenInfo, {Size = UDim2.new(0,0,0,0)})
			tween:Play()
		end
	end
end

pp.PromptHidden:Connect(hidePrompt)
1 Like

Did you try printing local tween = ts:Create(ui_Instance, tweenInfo, {Size = size}) the size? (it might be set to 0)

1 Like

yup it’s set to 0. :triumph:

i think my hidePrompt is updating the sizes to 0 in my sizeOfUI table

image

I’ll be completely frank here, I’m overlooking everything with a small hypothesis (so there’s a solid chance this is wrong, but I suggest trying it anyway).

What may be happening is that the prompt isn’t re-appearing because the disappearing tween is already in progress. A workaround I usually do is the following:

if tween then
tween:Pause()
tween = TS:Create(etc) -- note that this is global
tween:Play()
end


-- in a different part of the code
if tween then
tween:Pause() -- because setting it to nil has a delay
tween = TS:Create(etc)
tween:Play()
end

It may look really weird, but it basically checks if there’s already a tween in progress and pauses and replaces it if there is.

Edit: I’m not sure if you need to tween every instance of a UI for some reason, but by just tweening a Parent (or holder) Frame, every other element within it will also be tweened as a byproduct. This can help optimize your game.

Hope this helps!

2 Likes

hey man, thanks a million for your help.

i ended up solving it somehow. i’ll defo use your way for my stuff in the future. i need to fix my tweens as u said, i keep forgetting that i can just tween the whole thing :man_facepalming:

the issue was here

	local sizeofUI = getUISize()
local function showPrompt()
	local sizeofUI = getUISize()

	local tweenInfo = TweenInfo.new(1.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, false, 0)

	for _, ui_Instance in ipairs(PP_UI:GetDescendants()) do
		if ui_Instance:IsA("Frame") or ui_Instance:IsA("TextLabel") then
			for key, size in pairs(sizeofUI) do
				if ui_Instance.Name == key then
					local tween = ts:Create(ui_Instance, tweenInfo, {Size = size})
					tween:Play()
				end
			end
		end
	end
end

i think my show and hide tweens were overlapping each other and every single time that function was called it was setting it to 0 or something so i put the getUISize() here and it worked:

local sizeOfUI = {}

local function getUISize()
	-- Store UI instance sizes in the table
	for _, ui_Instance in ipairs(PP_UI:GetDescendants()) do
		if ui_Instance:IsA("Frame") or ui_Instance:IsA("TextLabel") then
			sizeOfUI[ui_Instance.Name] = ui_Instance.Size
		end
	end
end

getUISize()

Maybe this will work? Not sure though.

local sizeOfUI = {}

local function getUISize()

	--store ui instance size in table
	for _, ui_Instance in ipairs(PP_UI:GetDescendants()) do
		if ui_Instance:IsA("Frame") or ui_Instance:IsA("TextLabel") then
			sizeOfUI[ui_Instance.Name] = ui_Instance.Size
		end
	end

	return sizeOfUI
end

local function HideUI()
	-- Reset the sizes to 0 before scaling them up
	for _, ui_Instance in ipairs(PP_UI:GetDescendants()) do
		if ui_Instance:IsA("Frame") or ui_Instance:IsA("TextLabel") then
			ui_Instance.Size = UDim2.new(0, 0, 0, 0)  -- Reset to a small size
		end
	end
end



local function showPrompt()
	local sizeofUI = getUISize()

	local tweenInfo = TweenInfo.new(1.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, false, 0)

	for _, ui_Instance in ipairs(PP_UI:GetDescendants()) do
		if ui_Instance:IsA("Frame") or ui_Instance:IsA("TextLabel") then
			for key, size in pairs(sizeofUI) do
				if ui_Instance.Name == key then
					local tween = ts:Create(ui_Instance, tweenInfo, {Size = size})
					tween:Play()
HideUI()
				end
			end
		end
	end
end

pp.PromptShown:Connect(showPrompt)

local function hidePrompt()
	local tweenInfo = TweenInfo.new(1.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, false, 0)

	for _, ui_Instance in ipairs(PP_UI:GetDescendants()) do
		if ui_Instance:IsA("Frame") or ui_Instance:IsA("TextLabel") then
			local tween = ts:Create(ui_Instance, tweenInfo, {Size = UDim2.new(0,0,0,0)})
			tween:Play()
			showPrompt()
		end
	end
end

I added ShowPrompt() to the HidePrompt function

2 Likes

Nice! I’m glad you solved it. Make sure to mark your answer as a solution so other people don’t try to help with something that’s already fixed.

1 Like

If you didn’t know there’s an Instance called UIScale, you can just put it in the prompt and tween the Scale value, it’s very useful and I use it all the time

1 Like

oops my bad mate thanks for reminding me :+1:

1 Like

solution:

local sizeOfUI = {}

local function getUISize()

	-- Store UI instance sizes in the table
	for _, ui_Instance in ipairs(PP_UI:GetDescendants()) do
		if ui_Instance:IsA("Frame") or ui_Instance.Name == "actionText" then
			sizeOfUI[ui_Instance.Name] = ui_Instance.Size
		end
	end
	
	sizeOfUI[objText.Name] = objText.TextSize
	sizeOfUI[actionText.Name] = actionText.TextSize
end

getUISize()

local function HideUI()
	-- Reset the sizes to 0 before scaling them up
	for _, ui_Instance in ipairs(PP_UI:GetDescendants()) do
		if ui_Instance:IsA("Frame") then
			ui_Instance.Size = UDim2.new(0, 0, 0, 0)  -- Reset to a small size
		end
	end
	
	objText.TextSize = 0
	actionText.TextSize = 0
end

HideUI()

local function showPrompt()

	local tweenInfo = TweenInfo.new(TWEEN_TIME, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, false, 0)

	-- Tween to original sizes
	for _, ui_Instance in ipairs(PP_UI:GetDescendants()) do
		if ui_Instance:IsA("Frame") then
			local originalSize = sizeOfUI[ui_Instance.Name]
			if originalSize then
				local tween = ts:Create(ui_Instance, tweenInfo, {Size = originalSize})
				tween:Play()
			end
		end
	end
	
	local fontTween = ts:Create(objText, tweenInfo, {TextSize = sizeOfUI[objText.Name]})
	fontTween:Play()
	local fontTween2 = ts:Create(actionText, tweenInfo, {TextSize = sizeOfUI[actionText.Name]})
	fontTween2:Play()
end

local function hidePrompt()
	local tweenInfo = TweenInfo.new(TWEEN_TIME, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, false, 0)

	for _, ui_Instance in ipairs(PP_UI:GetDescendants()) do
		if ui_Instance:IsA("Frame") then
			local tween = ts:Create(ui_Instance, tweenInfo, {Size = UDim2.new(0, 0, 0, 0)})
			tween:Play()
		end
	end
	
	local fontTween = ts:Create(objText, tweenInfo, {TextSize = 0})
	fontTween:Play()
	local fontTween2 = ts:Create(actionText, tweenInfo, {TextSize = 0})
	fontTween2:Play()
end

pp.PromptShown:Connect(showPrompt)
pp.PromptHidden:Connect(hidePrompt)

oh wow i didnt know about that actually. only uicorner. thanks very much man, i’ll make sure not to forget that for next time!! :slight_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.