Making frame position, size and visibility change when player joins game

Hey, I’ve been trying to make it so that whenever the player has joined the game, the frame’s position, size and visibility changes. I’ve got this code written, but its not working. It may be an issue with some other part from my script, but id doubt it. This is my script:


local function onPlayerAdded(player)
	player.CharacterAdded:Connect(function(character)
		-- Get the ItemsFrame
		local ItemsFrame = player.PlayerGui:WaitForChild("ScreenGui").ItemsFrame

		-- Set the initial position and size
		ItemsFrame.Position = UDim2.new(1.1, 0, 0.5, 0)
		ItemsFrame.Size = UDim2.new(0.1, 0, 0.1, 0)
		ItemsFrame.Visible = false
	end)
end

-- Connect the onPlayerAdded function to the PlayerAdded event
game.Players.PlayerAdded:Connect(onPlayerAdded)

You could add a local script inside of StarterCharacterScripts and simply change the Gui there, since it’s inside of StarterCharacterScripts you do not need to have function or anything, simply change the Gui

is there still not a way to do this directly being in the same script? I don’t personally like everything being everywhere, and there’s more to this script, not only the function