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

TweenPosition moving to the wrong place?

Asked by 6 years ago

so here's the code:

 local ply = game.Players.LocalPlayer
local gui = ply:WaitForChild('PlayerGui'):WaitForChild('ScreenGui'):WaitForChild('Inventory')
local InventoryOpened = false

function onKeyPress(actionName, userInputState, inputObject)
    if userInputState == Enum.UserInputState.Begin then
        print("E was pressed")
        if InventoryOpened == false then
            gui:TweenPosition(UDim2.new({0.15, 0},{0.2, 0}), "InOut", "Quad", 1, true)
            InventoryOpened = true
        else
            print('should close here')
            gui:TweenPosition(UDim2.new({0.15, 0},{1, 0}), "InOut", "Quad", 1, true)
            InventoryOpened = false
        end
    end
end

game.ContextActionService:BindAction("keyPress", onKeyPress, false, Enum.KeyCode.E)

The 'Inventory' gui should move to {0.15, 0},{0.2, 0} but for some reason it moves to {0, 0},{0,0}. Also, the gui doesn't close when I press 'E' again.

Any help would be appreciated.

0
Should it not be Gui:TweenPosition(UDim2.new(0.15, 0.2, 0, 0)) ? ABK2017 406 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

When you are doing a TweenPosition, you would not include the {} around the set values.

So Instead of

 gui:TweenPosition(UDim2.new({0.15, 0},{0.2, 0}), "InOut", "Quad", 1, true)

You do

 gui:TweenPosition(UDim2.new(0.15, 0,0.2, 0), "InOut", "Quad", 1, true)
Ad

Answer this question