Help Making Weld On Keyboard Press Script

So, as the title suggests, I’m trying to make a script that can weld a part to a R15 player’s right hand after you click a button on the keyboard.

The issue is that I have tried so many different methods to make this work but nothing, half the Enum keycode scripts I attempted to recycle didn’t work how they originally were, and I tried to make about 10 scripts and not one worked.

I tried to find solutions here on the developer forums, nothing even related to my issue. I tried reddit, and you tube, no help. Still nothing happening.

And I forgot to mention this but this is for a vr game, but I will do that after I can get it working outside of VR and just recycle the script. But here is one of the codes I thought would work but didnt.

local playersAllowed = game.Players.ChildAdded

local plr = nil
function onKeyPress(inputObject, gameProcessedEvent)
	--ignore
end
for i=1,#playersAllowed do
	--ignore
		if plr.Name == playersAllowed[i] then
			--ignore
		end
	if inputObject.KeyCode == Enum.KeyCode.Q then
		--ignore
				local function weldPlayer(player)
					local character = player.Character
					local RH = character and character:FindFirstChild("RightHand")

					if character and RH then
						local weld = Instance.new("WeldConstraint")
						weld.Part0 = part
						weld.Part1 = RH
						weld.Parent = part
					end
				end

				part.Touched:Connect(function(hit)
				end)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)

		if player and not part:FindFirstChildWhichIsA("WeldConstraint") then weldPlayer(player)
		end
	end
end

Not gonna lie that script is pretty embarrassing but I tried my best for a builder, just help me revise it.

never mind, the script is horribly formatted so i didn’t see it.

are you using ‘’’lua formatting?

well to be fair, I know absolutely nohing about coding, So its best to ignore that script, I really jsut need help on what to ask the script for what i want to achieve to work.

have you even tried looking at the output

well it just says 13:25:43.698 Workspace.KeyCodeExample:8: attempt to get length of a RBXScriptSignal value - Server - KeyCodeExample:8, which i am too stupid to understand. If you can explain it please do.