为什么不补间位置?

Why isnt the position tweening?

我是 Lua 的新手,我正在尝试在 Roblox 中制作游戏。我目前正在我的 Miner GUI 上开发一个打开和关闭按钮。

代码

local Frame = script.Parent.Parent.Parent.Parent.Parent.MinerGuiManager.MinerFrame
local Opened = false
if Opened == false then
    print('Gui Is Closed')
    Opened = true
end
if Opened == true then 
    print('Gui Is Opened')
end
script.Parent.Button.MouseButton1Click:connect(function()
    GUI:TweenPosition(UDim2.new(1, 0, 1, 0),'Bounce',1.5)
    
    
end)

我希望 GUI 消失并重新出现

Game

GUIObject:TweenPosition 函数有几个参数。有些有默认值,但如果你想覆盖它们,你需要以正确的顺序覆盖它们。您的示例看起来缺少 easingDirection 参数。

此外,您需要在要设置动画的对象上调用 TweenPosition。在您的示例中,它将是变量 Frame.

-- define some variables and grab some UI elements relative to the script's location
local Button = script.Parent.Button
local Frame = script.Parent.Parent.Parent.Parent.Parent.MinerGuiManager.MinerFrame
local Opened = false

Button.MouseButton1Click:connect(function()
    local TargetPos
    if Opened then
        -- move the frame offscreen to the lower right
        -- NOTE - once we move it offscreen, we won't be able to click the button
        --        and bring it back onscreen... (change this number later)
        TargetPos = UDim2.new(1, 0, 1, 0)
    else
        -- move the frame to the center of the screen
        local frameWidthOffset = Frame.Size.X.Offset * -0.5
        local frameHeightOffset = Frame.Size.Y.Offset * -0.5
        TargetPos = UDim2.new(0.5, frameWidthOffset, 0.5, frameHeightOffset)
    end

    -- animate the frame to the target position over 1.5 seconds
    local EaseDir = Enum.EasingDirection.Out
    local EaseStyle = Enum.EasingStyle.Bounce
    Frame:TweenPosition(TargetPos, EaseDir, EaseStyle, 1.5)

    -- toggle the Opened value
    Opened = not Opened
end)