hi, i'm relatively new to scripting and i'm trying to make a door that opens when you get near it and press E.
i've been having trouble with my inputBegan function where it prints far too many times on one keypress and freezes the game momentarily when printing. Wait() did not work so i tried disconnect, although it seems to do nothing. i do have it in a repeat (.....) until loop, and ive considered this might be a problem, does anybody know?
am i using this wrong? can somebody explain a better way to stop my function from repeating more than once? my code is below
if active == true and v.Door then --is localplayer close enough to door
local connection
local function whywontthiswork(key) --prints over 300 times per input?
if key.KeyCode == Enum.KeyCode.E then
print("hello")
connection:Disconnect()
end
end
connection = UIService.InputBegan:Connect(whywontthiswork)
end
thank you for your time

1 comment
hi, thanks for the input but when tested they came out with the same results. i did however remove it from the repeat until loop that encompasses most of my script and it worked fine. thank you again