Size of gui not changing put disappearing even though its not supposed to?

I created this script that is supposed to change the size of a button when you hover over it, and then go back once you leave the hover, but when you hover its completely disappears, and when checked, both its position and size are 0. Here is the script.

local Player = game.Players.LocalPlayer

local Mouse = Player:GetMouse()

local Canvas = script.Parent

function showPointer()

Canvas.Size = UDim2.new{0.231, 0},{0.192, 0}

Canvas.Position = UDim2.new{0.384, 0},{0.701, 0}

end

function hidePointer()

Canvas.Size = UDim2.new{0.218, 0},{0.181, 0}

Canvas.Position = UDim2.new{0.391, 0},{0.701, 0}

end

Canvas.MouseEnter:Connect(showPointer)

Canvas.MouseLeave:Connect(hidePointer)

Instead of UDim2.new{0.218, 0},{0.181, 0}, use UDim2.new(0.213, 0, 0.181, 0).

Also, google how to use certain functions before going straight to the DevForum. The wiki page for UDim2’s show you how to construct one, and the wiki is always my first go-to. If not the wiki, then I google. If not then, THEN I post here.

Its for when the mouse enters, and leaving.

You’re using incorrect syntax for UDim2.new(). If you try to run that script, it will give you an error saying unexpected symbol near ',' because you’re using curly brackets instead of parentheses to call a function. Read my previous reply to see a solution to that, then go to the wiki page for UDim2 to see how to construct them.

I used parenthesis and now im getting that error?

What is the point of this? You’re calling UDim2.new with an array but it expects four numbers.
(second table is dropped, whats the point of it?)

Perhaps you meant to do something like this?

Canvas.Size = UDim2.new(0.231,0,0.192,0)

Script analysis says its fine, you can call functions without parenthesis if you only are passing a table or string.
i.e

print("hello")
--is the same thing as
print"hello"

pairs({})
--is the same thing as
pairs{}
1 Like

Oh true. I only tried running it in the command line in Studio.

Halalaluyafail3 is correct. You can’t call UDim2.new() with an array, you just need 4 numbers. Again, read the wiki page for UDim2 to see how to construct one properly.

I fixed it, nvm. Thank you. Updated code here.

local Player = game.Players.LocalPlayer

local Mouse = Player:GetMouse()

local Canvas = script.Parent

function showPointer()

Canvas.Size = UDim2.new(0.231, 0,0.192, 0)

Canvas.Position = UDim2.new(0.384, 0,0.701, 0)

end

function hidePointer()

Canvas.Size = UDim2.new(0.213, 0, 0.181, 0)

Canvas.Position = UDim2.new(0.391, 0,0.701, 0)

end

Canvas.MouseEnter:Connect(showPointer)

Canvas.MouseLeave:Connect(hidePointer)
1 Like