Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

GUI Error. Anyone know what this is?

Asked by
KordGamer 155
9 years ago

Hi! I'm making a GUI and i was tweening the size of a TextButton. When doing this, I encountered an error. The error was this:

Unable to cast double to token Script 'Players.KordGamer.PlayerGUI.ScreenGUI.Frame.CreditsButton.S', Line 2.

and Unable to cast double to token Script 'Players.KordGamer.PlayerGUI.ScreenGUI.Frame.CreditsButton.S', Line 6.

Here is the code :

function Hover()
    script.Parent:TweenSize(0.05, 200, 0.05, 50)
end

function StopHovering()
    script.Parent:TweenSize(0, 200, 0, 50)
end

function Click()
    --TODO: Make click function
end

script.Parent.MouseEnter:connect(Hover)
script.Parent.MouseLeave:connect(StopHovering)

Any help is appreciated. Thank you!

2 answers

Log in to vote
2
Answered by 9 years ago

The first argument of the TweenSize function is a UDim2 value. You're a using a number so the script will error. To fix this, you need to wrap those numbers around UDim2.new() inside the parenthesis. You will also need some extra arguments such as EasingDirection, EasingStyle and Time in order for the TweenSize function to work.

Overall, you script should look something like this:

function Hover()
    script.Parent:TweenSize(UDim2.new(0.05, 200, 0.05, 50),"Out","Quad",1,true) --Tweens the size in one second in the EasingDirection of Out and with the EasingStyle of Quad. You need the true at the end so you can do the StopHovering tween if it's called mid way through.
end

function StopHovering()
    script.Parent:TweenSize(UDim2.new(0, 200, 0, 50),"Out","Quad",1) --Tweens the size in one second in the EasingDirection of Out and with the EasingStyle of Quad. You need the true at the end so you can do the Hovering tween if it's called mid way through.
end

function Click()
    --TODO: Make click function
end

script.Parent.MouseEnter:connect(Hover)
script.Parent.MouseLeave:connect(StopHovering)

I hope my answer helped you. If it did, be sure to accept it.

0
Aw dang, you posted before me. By the way, the parameters after the UDim2 part is not necessary, they are already set by default SurVur 86 — 9y
0
I usually like to set them myself so I know they've been set correctly, but thanks anyway. Spongocardo 1991 — 9y
Ad
Log in to vote
2
Answered by
SurVur 86
9 years ago

function Hover() script.Parent:TweenSize(UDim2.new(0.05, 200, 0.05, 50)) end function StopHovering() script.Parent:TweenSize(UDim2.new(0, 200, 0, 50)) end function Click() --TODO: Make click function end script.Parent.MouseEnter:connect(Hover) script.Parent.MouseLeave:connect(StopHovering)

You have to create a UDim2 object using UDim2new(). Don't forget, there are more parameters that will allow greater customization!

Answer this question