Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

More Accurate way to change size?

When you hover ur mouse over the button, it increases in size. When it leaves it shrinks back to normal. This works fine until my mouse leaves while its increasing. Then it stays the increased size. How would I make it so when its increasing and your mouse leaves it stops?

story.MouseEnter:Connect(function()
	if script.Parent.Changing.Value == true then
		script.Parent.Changing.Value = false
		repeat wait()
			script.Parent.TextSize = script.Parent.TextSize + 2
		until script.Parent.TextSize == 100
		script.Parent.Changing.Value = true
	end
end)


story.MouseLeave:Connect(function()
	if script.Parent.Changing.Value == true then
		script.Parent.Changing.Value = false
		repeat wait()
			script.Parent.TextSize = script.Parent.TextSize - 2
		until script.Parent.TextSize <= 90
		script.Parent.TextSize = 90
		script.Parent.Changing.Value = true
	end
end)

2 answers

✓ Accepted answer

Use TweenService. It removes the need to interpolate yourself and will fix this problem.

I will assume you know how to set up Services so I will skim over that part.

TweenService works by creating a tween instance that contains all your movement data. It has 3 properties: the object you want to tween (this can be a 3d object, GUI or just any instance with numerical properties), a TweenInfo instance (this contains the information about your tween), and finally the parameters of the object you want to manipulate.

Just a little more about TweenInfo that you should know, it has a number of properties: the durration of the tween (in seconds), the interpolation method (Ex. Linear, Quadratic, Exponential, Back, etc.), the directions it should apply the interpolation (should it interpolate on the start to end, just on the start, etc.) and a couple more that you wont really need to worry about.

With that out of the way lets create a tween. For this I will be tweening the instance Part for one second with the interpolation method set to Circular, interpolating only on the way in, to a new position of 1, 0, 0.

Ex.

local Tween = TweenService:Create(Part, TweenInfo.new(1, Enum.EasingStyle.Circular, Enum.EasingDirection.In), {position = Vector3.new(1, 0, 0)})

Enums are just dictionaries for numbers, Enum.EasingStyle.Circular is actually just the number 8 but it makes it easier to remember when its written like this.

After the tween is set up you need to actually run it. This step is pretty easy.

Ex.

local Tween = TweenService:Create(Part, TweenInfo.new(1, Enum.EasingStyle.Circular, Enum.EasingDirection.In), {position = Vector3.new(1, 0, 0)})

Tween:Play()

Finally here's an example a little closer to your situation.

Ex.

local Tween = TweenService:Create(script.Parent, TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.In), {TextSize = 90})

Make sure to set the time and interpolation method to whatever you want.

1 comment

0

Definitely helped! Thank you sm for explaining Tween easily.

You can achieve that by creating two new booleans and checking both at the MouseEnter and MouseLeave.

local entering = false
local leaving = false

story.MouseEnter:Connect(function()
	entering = true
	leaving = false
	repeat wait()
		 --Code
	until script.Parent.TextSize == 100 and leaving = false
end)

--And the opposite of that
story.MouseLeave:Connect(function()
	entering = false
	leaving = true
	repeat wait()
		 --Code
	until script.Parent.TextSize <= 90 and entering = false
end)

--Combine this with your code

So if the "entering" event is running, and the "leaving" event starts, the entering stops. And if the leaving is running, and the entering starts, the leaving stops. It can be also done with a single boolean, but I think this way is easier to understand.

Let me know if it helped

1 comment

0

This also fixed it! Highly appreciate the help!

This discussion is preserved as it was. New answers, comments, and votes are closed.