I'm making a lootbox and when the player presses e while near the box they will get something. However, the connection will not be cut off in this script:
local uis = game:GetService("UserInputService")
local InputConnection
workspace.LootBox.AREA.Touched:Connect(function()
print("entered")
workspace.LootBox.Part.BillboardGui.Enabled = true
InputConnection = uis.InputBegan:Connect(function(input)
if input.UserInputType.Name == "Keyboard" and input.KeyCode.Name == "E" then
print("THIS WORKS IF PRINTED")
end
end)
end)
workspace.LootBox.AREA.TouchEnded:Connect(function()
workspace.LootBox.Part.BillboardGui.Enabled = false
print("left")
InputConnection:Disconnect()
end)
Even after leaving the area the player can press e and print the message.

1 comment
Is the script a LocalScript? UserInputService doesn't work on ServerScripts.