How do i make a gui move?

Hi there!
I’ve been trying to make a 2d game with a player but i dont know exactly how to move it and what’s going wrong in this script, there’s no errors in the console but the print never shows. Any ideas?

script:

-- Grab the variables.
local UserInputService = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer:WaitForChild("PlayerGui").Game.Canvas.Player

-- Function for moving
local function onInputBegan(input, _gameProcessed)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.D then
			Player.Position = Player.Position + Vector2.new(0,1,0,0)
			print("Player has moved.")
		end
	end
end

UserInputService.InputBegan:Connect(onInputBegan)

Instead of Vector2, try UDim2, since “Player” is a Gui object and its position is not a Vector2, but a UDim2 value.

2 Likes

Ah thank you!

didn’t know udim2 was a thing :sweat_smile:

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.