I need help moving a 2D image using the arrow keys

It’s been a hot minute since I coded Roblox Lua. I’m attempting to recreate the Osu gamemode Osu!catch into Roblox. Right now I’m struggling to even make the character movement. I’m trying to make a system where the catcher GUI moves to the right when you press the right arrow key, and the catcher moves to the left when the left arrow key is moved. I can’t get the script to work. What am I doing wrong?

3 Likes

Sounds dumb but is that server script or client script?

1 Like

Neither. It was on “Legacy”

Screenshot 2023-06-18 022835

Its a server Script as indicated by the header, so that’s why it aint working. UserInputService works only in LocalScripts.

1 Like

I put the all the code on a local script and it still doesn’t work.

Because you are referencing the gui in StartGui and not PlayerGui. The contents of the StarterGui are automatically copied to the PlayerGui when the player joins in, and it is the UI in PlayerGui which is seen by the player.

local player = game.Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")

local gui = path_to_gui
1 Like

So I change it to this?

local player = game.Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")

local gui = game.StarterGui.ScreenGui.Catcher

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(Input)
	if Input.KeyCode == Enum.KeyCode.Right then
		gui.Position.X.Offset = gui.Position.X.Offset + 0.1
	end
end)
local gui = playerGui:WaitForChild("ScreenGui"):WaitForChild("Catcher")
1 Like