Script for moving frame not working

  1. What do you want to achieve? So, I am trying to make a script that makes a frame go up, down, left, and right when pressing WASD.

  2. What is the issue?

    image

    image

    image

  3. What solutions have you tried so far? I’ve tried to have it add and subtract 0.001 from the frame position, but it keeps saying things like, “UDIM expected, got UDIM2” and “UDIM2 expected, got UDIM”. I’ve tried using UDIM, UDIM2 and Vector2, but they all come up as error.

Here’s what I currently have:

local Frame = script.Parent.Frame
local W = Enum.KeyCode.W
local A = Enum.KeyCode.A
local S = Enum.KeyCode.S
local D = Enum.KeyCode.D
local UIS = game:GetService("UserInputService")
local open = false

--What is causing the errors
local YNMove = Vector2.new(0, -0.001) --When W is pressed
local XNMove = Vector2.new(-0.001, 0) --When A is pressed
local YPMove = Vector2.new(0, 0.001) --When S is pressed
local XPMove = Vector2.new(0.001, 0) --When D is pressed

--When W is pressed
UIS.InputBegan:Connect(function(key, gp)
	if key.KeyCode == W then
		if UIS:GetFocusedTextBox() == nil then
			if open == false then
				open = true
				Frame.Position = Frame.Position.Y  + YNMove
			end
		end
	end
end)
2 Likes

The error may be because you are giving vector2 values, when it comes to ui you use udim or udim2 values, try changing vector2.new to UDIM.new

I’ve tried both UDIM.new and UDIM2.new (Shown above)

Frame.Position is a UDim2, while Frame.Position.Y is a UDim, and YNMove is a Vector2

UDims store scale and offset, so converting those Vector2s to compatible UDim values wouldn’t just be a matter of find-and-replace.
e.g.

Vector2.new(0, -0.001)

to

UDim.new(0, -0.001)

would work only if that -0.001 is intended to be offset, as UDim values only store either x or y positions, not both.