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

Getting "Unable to cast double UDim2" error with tweening UI?

So I'm tweening a basic frame from one position to another, and I get a UDim2 error, here is an example

:ServerSided Script, starter gui

script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Parent.BasicFrame:TweenPosition(0.557, 0,0.5, 0)
end)

The UI is not in a folder, nor done in an odd way, and it prints out

'Unable to cast double UDim2' so I tried another tweening method

script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Parent.BasicFrame:TweenPosition(0.557, 0,0.5, 0, "InOut", "Quint", 1)
end)

And it prints 'Unable to cast value to function'. I used the same exact method with many frames and it works fine, but this for some reason just doesn't, do you have an idea?

3 answers

try using tweenservice instead

2 comments

0

That has nothing to do with it. They are not giving the UDim2.

0

I guess it's broken lol

Hello your method is not working because you are not giving a UDim2 value.

here is what your code should look like:

script.Parent.MouseButton1Click:Connect(function()
    script.Parent.Parent.BasicFrame:TweenPosition(UDim2.new(0.557,0,0.5,0),Enum.EasingDirection.InOut,Enum.EasingStyle.Quint,1)
end)

You may find more info here; https://developer.roblox.com/en-us/api-reference/function/GuiObject/TweenPosition

As Gameplayer365247v2 said you can use tween service here is what the code would look like:

script.Parent.MouseButton1Click:Connect(function()
game:service('TweenService'):Create(script.Parent.Parent.BasicFrame,TweenInfo.new(1,Enum.EasingStyle.Quint,Enum.EasingDirection.InOut),{Position=UDim2.new(0.557,0,0.5,0)}):Play()
end)

You wrote UDIM2(aka the GUI element's position) as x,y,x,y. You can't just do that because the script expects a specific value, which is UDIM2. Let's say you have a part and you try to set it's position like this:

part.Position = 5,2,6

This is not possible. Because it expects a Vector3 value. Like this:

part.Position = Vector3.new(5,2,6)

This is similar to UDIM2.

Instead of saying

Frame.Position = 0.557, 0,0.5, 0

You're going to have to say

Frame.Position = UDim2.new(0.557, 0,0.5, 0)

To apply it to your scripts:

--// ServerSided script
script.Parent.MouseButton1Click:Connect(function()
    script.Parent.Parent.BasicFrame:TweenPosition(UDim2.new(0.557, 0,0.5, 0))
end)

--// ClientSided script
script.Parent.MouseButton1Click:Connect(function()
    script.Parent.Parent.BasicFrame:TweenPosition(UDim2.new(0.557, 0,0.5, 0), "InOut", "Quint", 1)
end)

Hope you learned something!

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