Tweening GUI ends up breaking them

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I’d like to be able to stop the gui objects from clipping into each other when hovering

  2. What is the issue? GUI seems to clip into each other while moving mouse over them rapidly
    https://gyazo.com/08f88a676df015246e0bcd890fd5a6fe

  3. What solutions have you tried so far? I’ve looked on the devforum I can’t seem to find anything relating to this issue, i’ve attempted to add waits to it but to no avail

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

--Declaring Variables
local Menu = script.Parent

local P = Menu.Play

local Se = Menu.Settings

local S = Menu.Shop

local G = Menu.GameModes

local C = Menu.Credits

local Ps = Menu.PrivateServers

local U = Menu.Updates

--End

--Setting up tweens
local Ts = game:GetService("TweenService")

--PlayButton

Menu.Play.Size = UDim2.new(0.171, 0, 0.214, 0)
Menu.Play.Position = UDim2.new(0.5, 0, 0.495, 0)

--GameModes

Menu.GameModes.Size = UDim2.new(0.171, 0, 0.15, 0)
Menu.GameModes.Position = UDim2.new(0.5, 0, 0.297, 0)

--Settings

Menu.Settings.Size = UDim2.new(0.171, 0, 0.214, 0)
Menu.Settings.Position = UDim2.new(0.598, 0, 0.284, 0)

--Shop

Menu.Shop.Size = UDim2.new(0.171, 0, 0.214, 0)
Menu.Shop.Position = UDim2.new(0.23, 0, 0.285, 0)

--Credits

Menu.Credits.Size = UDim2.new(0.171, 0, 0.214, 0)
Menu.Credits.Position = UDim2.new(0.23, 0, 0.525, 0)

--Updates

Menu.Updates.Size = UDim2.new(0.171, 0, 0.214, 0)
Menu.Updates.Position = UDim2.new(0.598, 0, 0.525, 0)

--Private Servers

Menu.PrivateServers.Size = UDim2.new(0.171, 0, 0.15, 0)
Menu.PrivateServers.Position = UDim2.new(0.5, 0, 0.702, 0)

-- End



--Play Button Hover

P.MouseEnter:Connect(function()
	P:TweenSizeAndPosition(
		UDim2.new(0.212, 0, 0.265, 0),
		UDim2.new(0.5, 0, 0.499, 0),
		Enum.EasingDirection.Out,
		Enum.EasingStyle.Sine,
		0.3,
		true,
		nil
	)
	C:TweenPosition(
		UDim2.new(0.215, 0, 0.562, 0),
		Enum.EasingDirection.Out,
		Enum.EasingStyle.Sine,
		0.3,
		true,
		nil
	)
	S:TweenPosition(
		UDim2.new(0.215, 0, 0.244, 0),
		Enum.EasingDirection.Out,
		Enum.EasingStyle.Sine,
		0.3,
		true,
		nil
	)
	U:TweenPosition(
		UDim2.new(0.617, 0, 0.562, 0),
		Enum.EasingDirection.Out,
		Enum.EasingStyle.Sine,
		0.3,
		true,
		nil
	)
	Se:TweenPosition(
		UDim2.new(0.617, 0, 0.244, 0),
		Enum.EasingDirection.Out,
		Enum.EasingStyle.Sine,
		0.3,
		true,
		nil
	)
	Ps:TweenPosition(
		UDim2.new(0.5, 0, 0.723, 0),
		Enum.EasingDirection.Out,
		Enum.EasingStyle.Sine,
		0.3,
		true,
		nil
	)
	G:TweenPosition(
		UDim2.new(0.5, 0, 0.272, 0),
		Enum.EasingDirection.Out,
		Enum.EasingStyle.Sine,
		0.3,
		true,
		nil
	)
end)

P.MouseLeave:Connect(function()
	P:TweenSizeAndPosition(
		UDim2.new(0.171, 0, 0.214, 0),
		UDim2.new(0.5, 0, 0.495, 0),
		Enum.EasingDirection.In,
		Enum.EasingStyle.Sine,
		0.3,
		true,
		nil
	)
	C:TweenPosition(
		UDim2.new(0.23, 0, 0.525, 0),
		Enum.EasingDirection.In,
		Enum.EasingStyle.Sine,
		0.3,
		true,
		nil
	)
	S:TweenPosition(
		UDim2.new(0.23, 0, 0.285, 0),
		Enum.EasingDirection.In,
		Enum.EasingStyle.Sine,
		0.3,
		true,
		nil
	)
	U:TweenPosition(
		UDim2.new(0.598, 0, 0.525, 0),
		Enum.EasingDirection.In,
		Enum.EasingStyle.Sine,
		0.3,
		true,
		nil
	)
	Se:TweenPosition(
		UDim2.new(0.598, 0, 0.284, 0),
		Enum.EasingDirection.In,
		Enum.EasingStyle.Sine,
		0.3,
		true,
		nil
	)
	Ps:TweenPosition(
		UDim2.new(0.5, 0, 0.702, 0),
		Enum.EasingDirection.In,
		Enum.EasingStyle.Sine,
		0.3,
		true,
		nil
	)
	G:TweenPosition(
		UDim2.new(0.5, 0, 0.297, 0),
		Enum.EasingDirection.In,
		Enum.EasingStyle.Sine,
		0.3,
		true,
		nil
	)
end)
wait(0.6)

--GameMode Tween

G.MouseEnter:Connect(function()
	G:TweenSizeAndPosition(
		UDim2.new(0.201, 0, 0.176, 0),
		UDim2.new(0.5, 0, 0.297, 0),
		Enum.EasingDirection.Out,
		Enum.EasingStyle.Sine,
		0.3,
		true,
		nil
	)
	P:TweenPosition(
		UDim2.new(0.5, 0, 0.519, 0),
		Enum.EasingDirection.Out,
		Enum.EasingStyle.Sine,
		0.3,
		true,
		nil
	)
	S:TweenPosition(
		UDim2.new(0.209, 0, 0.302, 0),
		Enum.EasingDirection.Out,
		Enum.EasingStyle.Sine,
		0.3,
		true,
		nil
	)
	Se:TweenPosition(
		UDim2.new(0.624, 0, 0.301, 0),
		Enum.EasingDirection.Out,
		Enum.EasingStyle.Sine,
		0.3,
		true,
		nil
	)
	U:TweenPosition(
		UDim2.new(0.624, 0, 0.542, 0),
		Enum.EasingDirection.Out,
		Enum.EasingStyle.Sine,
		0.3,
		true,
		nil
	)
	Ps:TweenPosition(
		UDim2.new(0.5, 0, 0.726, 0),
		Enum.EasingDirection.Out,
		Enum.EasingStyle.Sine,
		0.3,
		true,
		nil
	)
	C:TweenPosition(
		UDim2.new(0.209, 0, 0.542, 0),
		Enum.EasingDirection.Out,
		Enum.EasingStyle.Sine,
		0.3,
		true,
		nil
	)
end)


G.MouseLeave:Connect(function()
	G:TweenSizeAndPosition(
		UDim2.new(0.171, 0, 0.15, 0),
		UDim2.new(0.5, 0, 0.297, 0),
		Enum.EasingDirection.In,
		Enum.EasingStyle.Sine,
		0.3,
		true,
		nil
	)
	C:TweenPosition(
		UDim2.new(0.23, 0, 0.525, 0),
		Enum.EasingDirection.In,
		Enum.EasingStyle.Sine,
		0.3,
		true,
		nil
	)
	S:TweenPosition(
		UDim2.new(0.23, 0, 0.285, 0),
		Enum.EasingDirection.In,
		Enum.EasingStyle.Sine,
		0.3,
		true,
		nil
	)
	U:TweenPosition(
		UDim2.new(0.598, 0, 0.525, 0),
		Enum.EasingDirection.In,
		Enum.EasingStyle.Sine,
		0.3,
		true,
		nil
	)
	Se:TweenPosition(
		UDim2.new(0.598, 0, 0.284, 0),
		Enum.EasingDirection.In,
		Enum.EasingStyle.Sine,
		0.3,
		true,
		nil
	)
	Ps:TweenPosition(
		UDim2.new(0.5, 0, 0.702, 0),
		Enum.EasingDirection.In,
		Enum.EasingStyle.Sine,
		0.3,
		true,
		nil
	)
	P:TweenPosition(
		UDim2.new(0.5, 0, 0.495, 0),
		Enum.EasingDirection.In,
		Enum.EasingStyle.Sine,
		0.3,
		true,
		nil
	)
end)
wait(0.6)
--End

--Credits Tween

C.MouseEnter:Connect(function()
	C:TweenSizeAndPosition(
		UDim2.new(0.185, 0, 0.231, 0),
		UDim2.new(0.217, 0, 0.525, 0),
		Enum.EasingDirection.Out,
		Enum.EasingStyle.Sine,
		0.3,
		true,
		nil
	)
	G:TweenPosition(
		UDim2.new(0.509, 0, 0.276, 0),
		Enum.EasingDirection.Out,
		Enum.EasingStyle.Sine,
		0.3,
		true,
		nil
	)
	P:TweenPosition(
		UDim2.new(0.509, 0, 0.478, 0),
		Enum.EasingDirection.Out,
		Enum.EasingStyle.Sine,
		0.3,
		true,
		nil
	)
	Ps:TweenPosition(
		UDim2.new(0.509, 0, 0.681, 0),
		Enum.EasingDirection.Out,
		Enum.EasingStyle.Sine,
		0.3,
		true,
		nil
	)
	Se:TweenPosition(
		UDim2.new(0.605, 0, 0.263, 0),
		Enum.EasingDirection.Out,
		Enum.EasingStyle.Sine,
		0.3,
		true,
		nil
	)
	S:TweenPosition(
		UDim2.new(0.243, 0, 0.262, 0),
		Enum.EasingDirection.Out,
		Enum.EasingStyle.Sine,
		0.3,
		true,
		nil
	)
	U:TweenPosition(
		UDim2.new(0.605, 0, 0.504, 0),
		Enum.EasingDirection.Out,
		Enum.EasingStyle.Sine,
		0.3,
		true,
		nil
	)
end)
C.MouseLeave:Connect(function()
	C:TweenSizeAndPosition(
		UDim2.new(0.171, 0, 0.214, 0),
		UDim2.new(0.23, 0, 0.525, 0),
		Enum.EasingDirection.In,
		Enum.EasingStyle.Sine,
		0.3,
		true,
		nil
	)
	G:TweenPosition(
		UDim2.new(0.5, 0, 0.297, 0),
		Enum.EasingDirection.In,
		Enum.EasingStyle.Sine,
		0.3,
		true,
		nil
	)
	S:TweenPosition(
		UDim2.new(0.23, 0, 0.285, 0),
		Enum.EasingDirection.In,
		Enum.EasingStyle.Sine,
		0.3,
		true,
		nil
	)
	U:TweenPosition(
		UDim2.new(0.598, 0, 0.525, 0),
		Enum.EasingDirection.In,
		Enum.EasingStyle.Sine,
		0.3,
		true,
		nil
	)
	Se:TweenPosition(
		UDim2.new(0.598, 0, 0.284, 0),
		Enum.EasingDirection.In,
		Enum.EasingStyle.Sine,
		0.3,
		true,
		nil
	)
	Ps:TweenPosition(
		UDim2.new(0.5, 0, 0.702, 0),
		Enum.EasingDirection.In,
		Enum.EasingStyle.Sine,
		0.3,
		true,
		nil
	)
	P:TweenPosition(
		UDim2.new(0.5, 0, 0.495, 0),
		Enum.EasingDirection.In,
		Enum.EasingStyle.Sine,
		0.3,
		true,
		nil
	)
end)
wait(0.6)
--End

--Private Servers

Sorry for the lengthy code, I know that it stops at private servers I stopped so that way if there’s an issue with how I was going about this I can fix it without having to rewrite the code entirely

At the end of each tween where you write 0.3,true,nil, change nil to false.

image
It’s giving me this error now, only to the TweenSizeAndPosition

Try making a tween a function, return at the end of each tween and print what it returns.

If its working, it should return true.

How would I go about this? Sorry i’m new to scripting

function tween()

--code

if (guiname).Position == UDim2.new(where you want it to go) then
return true
else
return false
end
end

local result = tween()
if result == true then
print("Working, "..result)
else
print("Not working, "..result)
end

Would this work with MouseEnter or would I have to make a different thing for it

It should still work, if not use MouseMoved.

The problem is probably that mouse leave doesn’t always fire after mouse enter, especially when moving the mouse quickly or off the screen. It also might have to do with the tweens being canceled incorrectly.

I’d recommend two things:

  • First, maybe use this module to get more reliable MouseEnter and MouseLeave events:
  • Next, split your TweenSizeAndPosition function into TweenSize and TweenPosition, just in case the problem is also that the tween tweening size and position is being canceled (causing both tweens to stop, but then the size isn’t reset because the tween that canceled was only modifying position), causing the incorrect size. Alternatively, you can always use TweenSizeAndPosition.
1 Like