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

How to make a frame that moves along the x axis?

Asked by 3 years ago

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

1 answer

Log in to vote
1
Answered by
imKirda 4491 Moderation Voter Community Moderator
3 years ago

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.

Ad

Answer this question