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

TweenPosition moving to the wrong place?

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.

1 comment

0

Should it not be Gui:TweenPosition(UDim2.new(0.15, 0.2, 0, 0)) ?

1 answer

✓ Accepted answer

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)

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