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

TweenPosition error Unable to cast token to float?

Asked by 2 years ago

I'm making a gui that will go to the left the problem is at the comment --here is the problem

local TweenService = game:GetService("TweenService")
local frame = script.Parent.Parent.TextLabel
local Button = script.Parent
local Image = script.Parent.Parent.ImageLabel
frame.AnchorPoint = Vector2.new(0.023, 0.593)
frame.Position = UDim2.new(0.042, 0, 0.61, 0)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Button.MouseEnter:Connect(function(x, y)
    -- Declare target size and color values
    local newColor = Color3.fromRGB(255, 255, 255)
    local newsize = 50

    -- Set up tween
    local tweenInfo = TweenInfo.new(0.6, Enum.EasingStyle.Quart, Enum.EasingDirection.Out)
    local tween = TweenService:Create(frame, tweenInfo, { TextSize=newsize, TextColor3=newColor})

    tween:Play()

------------------------------------------------------------------------------------------------------------------------------------------------------  

    -- Declare target size and color values
    local ImageTrnsparency = 0

    -- Set up tween
    local tweenInfo = TweenInfo.new(0.6, Enum.EasingStyle.Quart, Enum.EasingDirection.Out)
    local tween = TweenService:Create(Image, tweenInfo, { ImageTransparency=ImageTrnsparency})

    tween:Play()


---------------------------------------------------------------------------------------------------------------------------------------------------------   

end)

Button.MouseLeave:Connect(function(x, y)
    -- Declare target size and color values
    local newColor = Color3.fromRGB(167, 167, 167)
    local newsize = 40

    -- Set up tween
    local tweenInfo = TweenInfo.new(0.6, Enum.EasingStyle.Quart, Enum.EasingDirection.Out)
    local tween = TweenService:Create(frame, tweenInfo, { TextSize=newsize, TextColor3=newColor})


    tween:Play()

    ------------------------------------------------------------------------------------------------------------------------------------------------------  

    -- Declare target size and color values
    local Trnsparency = 1

    -- Set up tween
    local tweenInfo = TweenInfo.new(0.6, Enum.EasingStyle.Quart, Enum.EasingDirection.Out)
    local tween = TweenService:Create(Image, tweenInfo, { ImageTransparency=Trnsparency})

    tween:Play()


end)


local function onActivated()
    Image.Image = "6981222571"  
    frame.TextColor3 = Color3.new(0, 1, 0.0509804)
    wait(0.2)
    Image.Image = "6975311587"
    frame.TextColor3 = Color3.new(255, 255, 255)
    wait(0.2)
    Image.Image = "6981222571"  
    frame.TextColor3 = Color3.new(0, 1, 0.0509804)
     --here is the problem
    frame:TweenPosition(UDim2.new( 0.042, 0 , 0.61, 0 ), 0.6, Enum.EasingStyle.Quart,                                                
        Enum.EasingDirection.Out )

end


Button.Activated:Connect(onActivated)

1 answer

Log in to vote
0
Answered by
TGazza 1336 Moderation Voter
2 years ago

You have your Declarations the wrong way round.

frame:TweenPosition(UDim2.new( 0.042, 0 , 0.61, 0 ),
     0.6, 
    Enum.EasingStyle.Quart,                                               
    Enum.EasingDirection.Out )

Should be:

frame:TweenPosition(
    UDim2.new( 0.042, 0 , 0.61, 0 ), 
    Enum.EasingStyle.Quart,                                      
    Enum.EasingDirection.Out,
    0.6)  --,Interrupt(tru/fal),Callback function)

Reference: (Taken from the wiki)

guiObject:TweenPosition(
    GOAL_POSITION,           -- Final position the tween should reach
    Enum.EasingDirection.In, -- Direction of the easing
    Enum.EasingStyle.Sine,   -- Kind of easing to apply
    2,                       -- Duration of the tween in seconds
    true,                    -- Whether in-progress tweens are interrupted
    callback                 -- Function to be called when on completion/cancelation
)

Wiki Link!

Hope this helps!

Ad

Answer this question