Hello, I wanted to make a script that uses the "E" button to move the frame. Unfortunately, something went wrong. Does anyone know how to reposition the x or y of the frame?
-- loop, while true do --when pressed D game:GetService("UserInputService").InputBegan:connect(function(inputObject, gameProcessedEvent) if inputObject.KeyCode == Enum.KeyCode.D then script.Parent.Player.Position.X = script.Parent.Player.Position.X+1 -- change position X of the player(player is a frame) end end) end
Your loop is useless in this case, :Connect
creates a connection which gets invoked every time you press a key, you don't need to connect it repeatedly (see this for more info).
You can't change X
property directly, you need to create new UDim2:
game:GetService("UserInputService").InputBegan:Connect(function(inputObject, gameProcessedEvent) if inputObject.KeyCode == Enum.KeyCode.D then script.Parent.Player.Position += UDim2.new(0, 1, 0, 0) -- change position X of the player(player is a frame) end end)
Prefer using :Connect
with uppercase "C" as the lowercase variant is deprecated.