Egg Hatching Pop Up E button doesnt work

Capture

Im tryna make an egg hatching system

I have pop up working for an egg saying “e” that works when you are 20 studs near
but i wanna make the button work when you press e on your keyboard. it doesnt work

robloxapp-20220127-1923287.wmv (771.0 KB)

script:

local Player = game.Players.LocalPlayer

local UserInputService = game:GetService(“UserInputService”)

local sp = script.Parent

if sp.Parent.CurrentDistance <= 20 and UserInputService:IsKeyDown(Enum.KeyCode.E) then

print(“script is working”)

end

in the video the script was to change the text of the button from “e” to “r”

Try this instead:

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(input)
	if (input.KeyCode == Enum.KeyCode.E) and (sp.Parent.CurrentDistance <= 20) then
		print("works")
	end
end)

You should read more about it here: UserInputService | Roblox Creator Documentation