the title says it all
im trying to make a text button that add size to it self when clicked and and stops when reached a certain size
any help will be appreciated
the title says it all
im trying to make a text button that add size to it self when clicked and and stops when reached a certain size
any help will be appreciated
You can use Udim2
,
script.Parent.MouseButton1Click:Connect(function()
if script.Parent.Size == UDim2.new(0,250,0,100) then return end
script.Parent.Size += UDim2.new(0,25,0,25)
end)
[Of course you could use TweenService
aswell, but this one is a basic one].
Lets explain what happens here :
script.Parent.MouseButton1Click:Connect(function()
end)
In this part, we’re firing an event called MouseButton1Click
, which will trigger whenever the player pressed/clicked on that TextButton.
if script.Parent.Size == UDim2.new(0,250,0,100) then return end
script.Parent.Size += UDim2.new(0,25,0,25)
Here, we’re checking the Side of the TextButton, if it’s at the maximum value it can get [accordingly to your choice], then we return end, which means, it will do nothing.
But, as long as it hasnt reached it yet, it’ll add size to it. Until it reaches its maximum.
Make sure that what you’re adding to your size, that text would be able to reach.
addition is the answer
if whatevertextbox.Size <= UDim2.new(prefered, prefered, prefered, prefered) then
whateverbox.Size += UDim2.new(prefered, prefered, prefered, prefered)
end
example
Thanks But when i tested the script
it went over the the certain size here is the script
ClickArea.MouseButton1Click:Connect(function()
sound:Play()
if script.Parent.Size == UDim2.new(0,562,0,28) then return end
script.Parent.Size += UDim2.new(0,80,0,0)
end)
You need to make sure that when you’re adding the size, it will fit and let the textbutton reach the size.
Meaning,
As I showed above,
Adding UDim2.new(0,25,0,25) to a TextButton’s size, if we want it to be able to reach UDim2.new(0,250,0,100), we must have numbers that can be divided by what we add. 250 can be divided by 25, and so does 100, thus it’ll work and reach its goal.
Or, you can simply change it to -
if script.Parent.Size + UDim2.new(0,80,0,0) >= UDim2.new(0,562,0,28) then return end
It still went over the certain size
and also this dosent work
if script.Parent.Size + UDim2.new(0,80,0,0) >= UDim2.new(0,562,0,28) then return end
--this script is broken
is their a way for the script to destory it self when reached that certain size?
if script.Parent.Size + UDim2.new(0,80,0,0) >= UDim2.new(0,562,0,28) then script.Parent:Destroy()
I modified your code and set it to destroy itself if the size is above the limit.
Sorry for bad formatting.
this error showed up
attempt to compare Udim2 <= Udim2
That is because Udim2
returns a table. You’ll have to check each value in the table manually.
This post is an example that explains it better:
script.Parent.MouseButton1Down:Connect(function()
script.Parent:TweenSize(UDim2.new(-- Size), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.2)
end)
LocalScript under the button! If you want it to pop back to the original position, you’ll need to manipulate it using UserInputService. Links:
https://developer.roblox.com/en-us/api-reference/class/UserInputService
https://developer.roblox.com/en-us/api-reference/function/GuiObject/TweenSize